+[](https://github.com/SixLabors/ImageSharp/actions)
+[](https://codecov.io/gh/SixLabors/ImageSharp)
[](https://raw.githubusercontent.com/SixLabors/ImageSharp/master/LICENSE)
[](https://gitter.im/ImageSharp/General?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://twitter.com/intent/tweet?hashtags=imagesharp,dotnet,oss&text=ImageSharp.+A+new+cross-platform+2D+graphics+API+in+C%23&url=https%3a%2f%2fgithub.com%2fSixLabors%2fImageSharp&via=sixlabors)
@@ -35,7 +37,6 @@ Install stable releases via Nuget; development releases are available via MyGet.
| Package Name | Release (NuGet) | Nightly (MyGet) |
|--------------------------------|-----------------|-----------------|
| `SixLabors.ImageSharp` | [](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) |
-| `SixLabors.ImageSharp.Drawing` | [](https://www.nuget.org/packages/SixLabors.ImageSharp.Drawing/) | [](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp.Drawing) |
### Packages
@@ -46,23 +47,15 @@ The **ImageSharp** library is made up of multiple packages:
- 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
-- **SixLabors.ImageSharp.Drawing**
- - Brushes and various drawing algorithms, including drawing images
- - Various vector drawing methods for drawing paths, polygons etc.
- - Text drawing
-
-### Build Status
-
-| |Build Status|Code Coverage|
-|-------------|:----------:|:-----------:|
-|**Linux/Mac**|[](https://travis-ci.org/SixLabors/ImageSharp)|[](https://codecov.io/gh/SixLabors/ImageSharp)|
-|**Windows** |[](https://ci.appveyor.com/project/six-labors/imagesharp/branch/master)|[](https://codecov.io/gh/SixLabors/ImageSharp)|
-
### Questions?
- Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. **Do not** open issues for questions!
- Please read our [Contribution Guide](https://github.com/SixLabors/ImageSharp/blob/master/.github/CONTRIBUTING.md) before opening issues or pull requests!
+### Code of Conduct
+This project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/) to clarify expected behavior in our community.
+For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
+
### API
Our API is designed to be simple to consume. Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
@@ -76,7 +69,7 @@ using SixLabors.ImageSharp.PixelFormats;
// Image.Load(string path) is a shortcut for our default type.
// Other pixel formats use Image.Load(string path))
-using (Image image = Image.Load("foo.jpg"))
+using (Image image = Image.Load("foo.jpg"))
{
image.Mutate(x => x
.Resize(image.Width / 2, image.Height / 2)
@@ -109,9 +102,9 @@ For more examples check out:
If you prefer, you can compile ImageSharp yourself (please do and help!)
-- Using [Visual Studio 2017](https://visualstudio.microsoft.com/vs/)
+- Using [Visual Studio 2019](https://visualstudio.microsoft.com/vs/)
- Make sure you have the latest version installed
- - Make sure you have [the .NET Core 2.1 SDK](https://www.microsoft.com/net/core#windows) installed
+ - Make sure you have [the .NET Core 3.1 SDK](https://www.microsoft.com/net/core#windows) installed
Alternatively, you can work from command line and/or with a lightweight editor on **both Linux/Unix and Windows**:
@@ -151,6 +144,7 @@ Core Team
- [Dirk Lemstra](https://github.com/dlemstra)
- [Anton Firsov](https://github.com/antonfirsov)
- [Scott Williams](https://github.com/tocsoft)
+- [Brian Popow](https://github.com/brianpopow)
### Backers
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 2cc5182d39..0000000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-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
-
-environment:
- matrix:
- - target_framework: netcoreapp2.1
- is_32bit: False
-
- - target_framework: netcoreapp2.1
- is_32bit: True
-
- - target_framework: net472
- is_32bit: False
-
- - target_framework: net472
- is_32bit: True
-
- - target_framework: net462
- is_32bit: False
-
- - target_framework: net462
- is_32bit: True
-
- #- target_framework: mono
- # is_32bit: False
- #- target_framework: mono
- # is_32bit: True
- #- target_framework: net47
- # is_32bit: False
- #- target_framework: net47
- # is_32bit: True
-
-install:
- - ps: |
- if ($env:target_framework -eq "mono") {
- if ($env:is_32bit -eq "True") {
- cinst mono --x86
- } else {
- cinst mono
- }
- }
-
-before_build:
- - git submodule -q update --init
- - cmd: dotnet --info
-
-build_script:
-- cmd: build.cmd
-
-test_script:
-- ps: .\run-tests.ps1 $env:target_framework $env:is_32bit
-
-after_test:
- - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.%APPVEYOR_BUILD_VERSION%.nupkg"
- - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Drawing.%APPVEYOR_BUILD_VERSION%.nupkg"
-
-deploy:
- # MyGet Deployment for builds & releases
- - 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
\ No newline at end of file
diff --git a/build.cmd b/build.cmd
deleted file mode 100644
index 6372b41253..0000000000
--- a/build.cmd
+++ /dev/null
@@ -1,17 +0,0 @@
-@echo Off
-
-PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
-
-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.ps1 b/build.ps1
deleted file mode 100644
index 215b551170..0000000000
--- a/build.ps1
+++ /dev/null
@@ -1,122 +0,0 @@
-
-# lets calulat the correct version here
-$fallbackVersion = "1.0.0";
-$version = ''
-
-$tagRegex = '^v?(\d+\.\d+\.\d+)(-([a-zA-Z]+)\.?(\d*))?$'
-
-# we are running on the build server
-$isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex
-
- if($isVersionTag) {
-
- Write-Debug "Building commit tagged with a compatable version number"
-
- $version = $matches[1]
- $postTag = $matches[3]
- $count = $matches[4]
- Write-Debug "version number: ${version} post tag: ${postTag} count: ${count}"
- if("$postTag" -ne ""){
- $version = "${version}-${postTag}"
- }
- if("$count" -ne ""){
- # for consistancy with previous releases we pad the counter to only 4 places
- $padded = $count.Trim().Trim('0').PadLeft(4,"0");
- Write-Debug "count '$count', padded '${padded}'"
-
- $version = "${version}${padded}"
- }
- }
- else {
-
- Write-Debug "Untagged"
- $lastTag = (git tag --list --sort=-taggerdate) | Out-String
- $list = $lastTag.Split("`n")
- foreach ($tag in $list) {
-
- Write-Debug "testing ${tag}"
- $tag = $tag.Trim();
- if($tag -match $tagRegex){
- Write-Debug "matched ${tag}"
- $version = $matches[1];
- break;
- }
- }
-
- if("$version" -eq ""){
- $version = $fallbackVersion
- Write-Debug "Failed to discover base version Fallback to '${version}'"
- }else{
-
- Write-Debug "Discovered base version from tags '${version}'"
- }
-
- $buildNumber = $env:APPVEYOR_BUILD_NUMBER
-
- # build number replacement is padded to 6 places
- $buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(6,"0");
- if("$env:APPVEYOR_PULL_REQUEST_NUMBER" -ne ""){
- Write-Debug "building a PR"
-
- $prNumber = "$env:APPVEYOR_PULL_REQUEST_NUMBER".Trim().Trim('0').PadLeft(5,"0");
- # this is a PR
- $version = "${version}-PullRequest${prNumber}${buildNumber}";
- }else{
- Write-Debug "building a branch commit"
-
- # this is a general branch commit
- $branch = $env:APPVEYOR_REPO_BRANCH
-
- if("$branch" -eq ""){
- $branch = ((git rev-parse --abbrev-ref HEAD) | Out-String).Trim()
-
- if("$branch" -eq ""){
- $branch = "unknown"
- }
- }
-
- $branch = $branch.Replace("/","-").ToLower()
-
- if($branch.ToLower() -eq "master"){
- $branch = "dev"
- }
-
- $version = "${version}-${branch}${buildNumber}";
- }
- }
-
-if("$env:APPVEYOR_API_URL" -ne ""){
- # update appveyor build number for this build
- Invoke-RestMethod -Method "PUT" `
- -Uri "${env:APPVEYOR_API_URL}api/build" `
- -Body "{version:'${version}'}" `
- -ContentType "application/json"
-}
-
-Write-Host "Building version '${version}'"
-dotnet restore /p:packageversion=$version /p:DisableImplicitNuGetFallbackFolder=true
-
-Write-Host "Building projects"
-dotnet build -c Release /p:packageversion=$version
-
-if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
-
-#
-# TODO: DO WE NEED TO RUN TESTS IMPLICITLY?
-#
-# if ( $env:CI -ne "True") {
-# cd ./tests/ImageSharp.Tests/
-# dotnet xunit -nobuild -c Release -f netcoreapp2.0 --fx-version 2.0.0
-# ./RunExtendedTests.cmd
-# cd ../..
-# }
-#
-
-if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
-
-Write-Host "Packaging projects"
-dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build /p:packageversion=$version
-if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
-
-dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build /p:packageversion=$version
-if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
diff --git a/build/icons/imagesharp-logo-128.png b/build/icons/imagesharp-logo-128.png
deleted file mode 100644
index 5c2079144f..0000000000
--- a/build/icons/imagesharp-logo-128.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:148a268c589b628f5d0b5af0e86911a0b393c35b8b25233c71553657c88e0b96
-size 7568
diff --git a/build/icons/imagesharp-logo-256.png b/build/icons/imagesharp-logo-256.png
deleted file mode 100644
index e38807ae1e..0000000000
--- a/build/icons/imagesharp-logo-256.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:7e4b2ff72aef1979500cd130c28490a00be116bb833bc96ca30c85dc0596099c
-size 15413
diff --git a/build/icons/imagesharp-logo-32.png b/build/icons/imagesharp-logo-32.png
deleted file mode 100644
index 273b171eb2..0000000000
--- a/build/icons/imagesharp-logo-32.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:021c12313afbdc65f58bfea8c7b436d5c2102513bb63d9e64ee2b61a1344c56a
-size 1799
diff --git a/build/icons/imagesharp-logo-512.png b/build/icons/imagesharp-logo-512.png
deleted file mode 100644
index 707dc9a35b..0000000000
--- a/build/icons/imagesharp-logo-512.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf
-size 32534
diff --git a/build/icons/imagesharp-logo-64.png b/build/icons/imagesharp-logo-64.png
deleted file mode 100644
index 17577772eb..0000000000
--- a/build/icons/imagesharp-logo-64.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:92896854265693f28f9a503b9093cb2c9a4a9b329f310732efdd9c6f6c3761bc
-size 3736
diff --git a/build/icons/imagesharp-logo.png b/build/icons/imagesharp-logo.png
deleted file mode 100644
index 707dc9a35b..0000000000
--- a/build/icons/imagesharp-logo.png
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf
-size 32534
diff --git a/build/icons/imagesharp-logo.svg b/build/icons/imagesharp-logo.svg
deleted file mode 100644
index 620287457a..0000000000
--- a/build/icons/imagesharp-logo.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/ci-build.ps1 b/ci-build.ps1
new file mode 100644
index 0000000000..17c6e6603b
--- /dev/null
+++ b/ci-build.ps1
@@ -0,0 +1,13 @@
+param(
+ [Parameter(Mandatory, Position = 0)]
+ [string]$version,
+ [Parameter(Mandatory = $true, Position = 1)]
+ [string]$targetFramework
+)
+
+dotnet clean -c Release
+
+$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
+
+# Building for a specific framework.
+dotnet build -c Release -f $targetFramework /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl
diff --git a/ci-pack.ps1 b/ci-pack.ps1
new file mode 100644
index 0000000000..a4e846db95
--- /dev/null
+++ b/ci-pack.ps1
@@ -0,0 +1,11 @@
+param(
+ [Parameter(Mandatory, Position = 0)]
+ [string]$version
+)
+
+dotnet clean -c Release
+
+$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
+
+# Building for packing and publishing.
+dotnet pack -c Release --output "$PSScriptRoot/artifacts" /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl
diff --git a/ci-test.ps1 b/ci-test.ps1
new file mode 100644
index 0000000000..3915ae4ccd
--- /dev/null
+++ b/ci-test.ps1
@@ -0,0 +1,37 @@
+param(
+ [Parameter(Mandatory, Position = 0)]
+ [string]$os,
+ [Parameter(Mandatory, Position = 1)]
+ [string]$targetFramework,
+ [Parameter(Mandatory, Position = 2)]
+ [string]$platform,
+ [Parameter(Mandatory, Position = 3)]
+ [string]$codecov,
+ [Parameter(Position = 4)]
+ [string]$codecovProfile = 'Release'
+)
+
+$netFxRegex = '^net\d+'
+
+if ($codecov -eq 'true') {
+
+ # Allow toggling of profile to workaround any potential JIT errors caused by code injection.
+ dotnet clean -c $codecovProfile
+ dotnet test --collect "XPlat Code Coverage" --settings .\tests\coverlet.runsettings -c $codecovProfile -f $targetFramework /p:CodeCov=true
+}
+elseif ($platform -eq '-x86' -and $targetFramework -match $netFxRegex) {
+
+ # xunit doesn't run on core with NET SDK 3.1+.
+ # xunit doesn't actually understand -x64 as an option.
+ #
+ # xunit requires explicit path.
+ Set-Location $env:XUNIT_PATH
+
+ dotnet xunit --no-build -c Release -f $targetFramework ${fxVersion} $platform
+
+ Set-Location $PSScriptRoot
+}
+else {
+
+ dotnet test --no-build -c Release -f $targetFramework
+}
diff --git a/codecov.yml b/codecov.yml
index ae6dd5f6bf..833fc0a51a 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -1,4 +1,11 @@
-ignore:
- "src/ImageSharp/Common/Helpers/DebugGuard.cs"
+# Documentation: https://docs.codecov.io/docs/codecov-yaml
-
\ No newline at end of file
+codecov:
+ # Avoid "Missing base report"
+ # https://github.com/codecov/support/issues/363
+ # https://docs.codecov.io/docs/comparing-commits
+ allow_coverage_offsets: true
+
+ # Avoid Report Expired
+ # https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
+ max_report_age: off
diff --git a/run-tests.ps1 b/run-tests.ps1
deleted file mode 100644
index 4aeaa14908..0000000000
--- a/run-tests.ps1
+++ /dev/null
@@ -1,112 +0,0 @@
-param(
- [string]$targetFramework,
- [string]$is32Bit = "False"
-)
-
-if (!$targetFramework){
- Write-Host "run-tests.ps1 ERROR: targetFramework is undefined!"
- exit 1
-}
-
-function VerifyPath($path, $errorMessage) {
- if (!(Test-Path -Path $path)) {
- Write-Host "run-tests.ps1 $errorMessage `n $xunitRunnerPath"
- exit 1
- }
-}
-
-function CheckSubmoduleStatus() {
- $submoduleStatus = (git submodule status) | Out-String
- # if the result string is empty, the command failed to run (we didn't capture the error stream)
- if ($submoduleStatus) {
- # git has been called successfully, what about the status?
- if (($submoduleStatus -match "\-") -or ($submoduleStatus -match "\(\(null\)\)"))
- {
- # submodule has not been initialized!
- return 2;
- }
- elseif ($submoduleStatus -match "\+")
- {
- # submodule is not synced:
- return 1;
- }
- else {
- # everything fine:
- return 0;
- }
- } else {
- # git call failed, so we should warn
- return 3;
- }
-}
-
-
-if ( ($targetFramework -eq "netcoreapp2.1") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) {
- # We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.1 + 64bit )
- $testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd"
-}
-elseif ($targetFramework -eq "mono") {
- $testDllPath = "$PSScriptRoot\tests\ImageSharp.Tests\bin\Release\net462\SixLabors.ImageSharp.Tests.dll"
- VerifyPath($testDllPath, "test dll missing:")
-
- $xunitRunnerPath = "${env:HOMEPATH}\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\"
-
- VerifyPath($xunitRunnerPath, "xunit console runner is missing on path:")
-
- cd "$xunitRunnerPath"
-
- if ($is32Bit -ne "True") {
- $monoPath = "${env:PROGRAMFILES}\Mono\bin\mono.exe"
- }
- else {
- $monoPath = "${env:ProgramFiles(x86)}\Mono\bin\mono.exe"
- }
-
- VerifyPath($monoPath, "mono runtime missing:")
-
- $testRunnerCmd = "& `"${monoPath}`" .\xunit.console.exe `"${testDllPath}`""
-}
-else {
- cd .\tests\ImageSharp.Tests
- $xunitArgs = "-nobuild -c Release -framework $targetFramework"
-
- if ($targetFramework -eq "netcoreapp2.1") {
- # There were issues matching the correct installed runtime if we do not specify it explicitly:
- $xunitArgs += " --fx-version 2.1.0"
- }
-
- if ($is32Bit -eq "True") {
- $xunitArgs += " -x86"
- }
-
- $testRunnerCmd = "dotnet xunit $xunitArgs"
-}
-
-Write-Host "running:"
-Write-Host $testRunnerCmd
-Write-Host "..."
-
-Invoke-Expression $testRunnerCmd
-
-cd $PSScriptRoot
-
-$exitCodeOfTests = $LASTEXITCODE;
-
-if (0 -ne ([int]$exitCodeOfTests)) {
- # check submodule status
- $submoduleStatus = CheckSubmoduleStatus
- if ([int]$submoduleStatus -eq 1) {
- # not synced
- Write-Host -ForegroundColor Yellow "Check if submodules are up to date. You can use 'git submodule update' to fix this";
- } elseif ($submoduleStatus -eq 2) {
- # not initialized
- Write-Host -ForegroundColor Yellow "Check if submodules are initialized. You can run 'git submodule init' to initialize them."
- } elseif ($submoduleStatus -eq 3) {
- # git not found, maybe submodules not synced?
- Write-Host -ForegroundColor Yellow "Could not check if submodules are initialized correctly. Maybe git is not installed?"
- } else {
- #Write-Host "Submodules are up to date";
- }
-}
-
-exit $exitCodeOfTests
diff --git a/shared-infrastructure b/shared-infrastructure
index faf84e44ec..ea561c249b 160000
--- a/shared-infrastructure
+++ b/shared-infrastructure
@@ -1 +1 @@
-Subproject commit faf84e44ec90e8a42a7271bcd04fea76279efb08
+Subproject commit ea561c249ba86352fe3b69e612b8072f3652eacb
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 6fbbb7c916..a78a75d428 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -22,20 +22,18 @@
true
-
-
-
+
+ true
+
+
-
-
-
-
+
+
+
-
-
-
+
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index c0e01ae586..d7171aa0f6 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -50,6 +50,26 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
deleted file mode 100644
index 5a53d3e78b..0000000000
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
- SixLabors.ImageSharp.Drawing
- SixLabors.ImageSharp.Drawing
- An extension to ImageSharp that allows the drawing of images, paths, and text.
- SixLabors.ImageSharp.Drawing
- Image Draw Shape Path Font
- SixLabors.ImageSharp
- netcoreapp2.1;netstandard1.3;netstandard2.0
-
-
-
-
- $(DefineConstants);SUPPORTS_MATHF
-
-
-
- $(DefineConstants);SUPPORTS_HASHCODE
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj.DotSettings b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj.DotSettings
deleted file mode 100644
index a728b54979..0000000000
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj.DotSettings
+++ /dev/null
@@ -1,2 +0,0 @@
-
- True
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Primitives/Region.cs b/src/ImageSharp.Drawing/Primitives/Region.cs
deleted file mode 100644
index 27f039f122..0000000000
--- a/src/ImageSharp.Drawing/Primitives/Region.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Primitives
-{
- ///
- /// Represents a region of an image.
- ///
- public abstract class Region
- {
- ///
- /// Gets the maximum number of intersections to could be returned.
- ///
- public abstract int MaxIntersections { get; }
-
- ///
- /// Gets the bounding box that entirely surrounds this region.
- ///
- ///
- /// This should always contains all possible points returned from .
- ///
- public abstract Rectangle Bounds { get; }
-
- ///
- /// Scans the X axis for intersections at the Y axis position.
- ///
- /// The position along the y axis to find intersections.
- /// The buffer.
- /// A instance in the context of the caller.
- /// The number of intersections found.
- public abstract int Scan(float y, Span buffer, Configuration configuration);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Primitives/ShapePath.cs b/src/ImageSharp.Drawing/Primitives/ShapePath.cs
deleted file mode 100644
index a4fef66a67..0000000000
--- a/src/ImageSharp.Drawing/Primitives/ShapePath.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.Processing;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Primitives
-{
- ///
- /// A mapping between a and a region.
- ///
- internal class ShapePath : ShapeRegion
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The shape.
- /// The pen to apply to the shape.
- public ShapePath(IPath shape, IPen pen)
- : base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern))
- {
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
deleted file mode 100644
index f4a6458206..0000000000
--- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Memory;
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Primitives
-{
- ///
- /// A mapping between a and a region.
- ///
- internal class ShapeRegion : Region
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The shape.
- public ShapeRegion(IPath shape)
- {
- this.Shape = shape.AsClosedPath();
- int left = (int)MathF.Floor(shape.Bounds.Left);
- int top = (int)MathF.Floor(shape.Bounds.Top);
-
- int right = (int)MathF.Ceiling(shape.Bounds.Right);
- int bottom = (int)MathF.Ceiling(shape.Bounds.Bottom);
- this.Bounds = Rectangle.FromLTRB(left, top, right, bottom);
- }
-
- ///
- /// Gets the fillable shape
- ///
- public IPath Shape { get; }
-
- ///
- public override int MaxIntersections => this.Shape.MaxIntersections;
-
- ///
- public override Rectangle Bounds { get; }
-
- ///
- public override int Scan(float y, Span buffer, Configuration configuration)
- {
- var start = new PointF(this.Bounds.Left - 1, y);
- var end = new PointF(this.Bounds.Right + 1, y);
-
- using (IMemoryOwner tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length))
- {
- Span innerBuffer = tempBuffer.GetSpan();
- int count = this.Shape.FindIntersections(start, end, innerBuffer);
-
- for (int i = 0; i < count; i++)
- {
- buffer[i] = innerBuffer[i].X;
- }
-
- return count;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs
deleted file mode 100644
index 7e75d7effc..0000000000
--- a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Memory;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// primitive that converts a point in to a color for discovering the fill color based on an implementation
- ///
- /// The pixel format.
- ///
- public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush
- where TPixel : struct, IPixel
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- /// The options.
- internal BrushApplicator(ImageFrame target, GraphicsOptions options)
- {
- this.Target = target;
- this.Options = options;
- this.Blender = PixelOperations.Instance.GetPixelBlender(options);
- }
-
- ///
- /// Gets the blender
- ///
- internal PixelBlender Blender { get; }
-
- ///
- /// Gets the destination
- ///
- protected ImageFrame Target { get; }
-
- ///
- /// Gets the blend percentage
- ///
- protected GraphicsOptions Options { get; }
-
- ///
- /// Gets the color for a single pixel.
- ///
- /// The x coordinate.
- /// The y coordinate.
- /// The a that should be applied to the pixel.
- internal abstract TPixel this[int x, int y] { get; }
-
- ///
- public abstract void Dispose();
-
- ///
- /// Applies the opacity weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
- ///
- /// The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.
- /// The x position in the target pixel space that the start of the scanline data corresponds to.
- /// The y position in the target pixel space that whole scanline corresponds to.
- /// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.
- internal virtual void Apply(Span scanline, int x, int y)
- {
- MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
-
- using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length))
- using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length))
- {
- Span amountSpan = amountBuffer.GetSpan();
- Span overlaySpan = overlay.GetSpan();
-
- for (int i = 0; i < scanline.Length; i++)
- {
- if (this.Options.BlendPercentage < 1)
- {
- amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
- }
- else
- {
- amountSpan[i] = scanline[i];
- }
-
- overlaySpan[i] = this[x + i, y];
- }
-
- Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(this.Target.Configuration, destinationRow, destinationRow, overlaySpan, amountSpan);
- }
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Brushes.cs b/src/ImageSharp.Drawing/Processing/Brushes.cs
deleted file mode 100644
index bd10e90c68..0000000000
--- a/src/ImageSharp.Drawing/Processing/Brushes.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// A collection of methods for creating generic brushes.
- ///
- /// A New
- public static class Brushes
- {
- ///
- /// Percent10 Hatch Pattern
- ///
- /// ---> x axis
- /// ^
- /// | y - axis
- /// |
- /// see PatternBrush for details about how to make new patterns work
- private static readonly bool[,] Percent10Pattern =
- {
- { true, false, false, false },
- { false, false, false, false },
- { false, false, true, false },
- { false, false, false, false }
- };
-
- ///
- /// Percent20 pattern.
- ///
- private static readonly bool[,] Percent20Pattern =
- {
- { true, false, false, false },
- { false, false, true, false },
- { true, false, false, false },
- { false, false, true, false }
- };
-
- ///
- /// Horizontal Hatch Pattern
- ///
- private static readonly bool[,] HorizontalPattern =
- {
- { false },
- { true },
- { false },
- { false }
- };
-
- ///
- /// Min Pattern
- ///
- private static readonly bool[,] MinPattern =
- {
- { false },
- { false },
- { false },
- { true }
- };
-
- ///
- /// Vertical Pattern
- ///
- private static readonly bool[,] VerticalPattern =
- {
- { false, true, false, false },
- };
-
- ///
- /// Forward Diagonal Pattern
- ///
- private static readonly bool[,] ForwardDiagonalPattern =
- {
- { false, false, false, true },
- { false, false, true, false },
- { false, true, false, false },
- { true, false, false, false }
- };
-
- ///
- /// Backward Diagonal Pattern
- ///
- private static readonly bool[,] BackwardDiagonalPattern =
- {
- { true, false, false, false },
- { false, true, false, false },
- { false, false, true, false },
- { false, false, false, true }
- };
-
- ///
- /// Create as brush that will paint a solid color
- ///
- /// The color.
- /// A New
- public static SolidBrush Solid(Color color) => new SolidBrush(color);
-
- ///
- /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush Percent10(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, Percent10Pattern);
-
- ///
- /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush Percent10(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, Percent10Pattern);
-
- ///
- /// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush Percent20(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, Percent20Pattern);
-
- ///
- /// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush Percent20(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, Percent20Pattern);
-
- ///
- /// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush Horizontal(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, HorizontalPattern);
-
- ///
- /// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush Horizontal(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, HorizontalPattern);
-
- ///
- /// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush Min(Color foreColor) => new PatternBrush(foreColor, Color.Transparent, MinPattern);
-
- ///
- /// Create as brush that will paint a Min Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush Min(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, MinPattern);
-
- ///
- /// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush Vertical(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, VerticalPattern);
-
- ///
- /// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush Vertical(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, VerticalPattern);
-
- ///
- /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush ForwardDiagonal(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, ForwardDiagonalPattern);
-
- ///
- /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
-
- ///
- /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
- /// transparent background.
- ///
- /// Color of the foreground.
- /// A New
- public static PatternBrush BackwardDiagonal(Color foreColor) =>
- new PatternBrush(foreColor, Color.Transparent, BackwardDiagonalPattern);
-
- ///
- /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A New
- public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) =>
- new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/ColorStop.cs b/src/ImageSharp.Drawing/Processing/ColorStop.cs
deleted file mode 100644
index 21c82b63ff..0000000000
--- a/src/ImageSharp.Drawing/Processing/ColorStop.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System.Diagnostics;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// A struct that defines a single color stop.
- ///
- [DebuggerDisplay("ColorStop({Ratio} -> {Color}")]
- public readonly struct ColorStop
- {
- ///
- /// Initializes a new instance of the struct.
- ///
- /// Where should it be? 0 is at the start, 1 at the end of the Gradient.
- /// What color should be used at that point?
- public ColorStop(float ratio, in Color color)
- {
- this.Ratio = ratio;
- this.Color = color;
- }
-
- ///
- /// Gets the point along the defined gradient axis.
- ///
- public float Ratio { get; }
-
- ///
- /// Gets the color to be used.
- ///
- public Color Color { get; }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs b/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs
deleted file mode 100644
index 25a8204f2a..0000000000
--- a/src/ImageSharp.Drawing/Processing/DrawingHelpers.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- internal static class DrawingHelpers
- {
- ///
- /// Convert a to a of the given pixel type.
- ///
- public static DenseMatrix ToPixelMatrix(this DenseMatrix colorMatrix, Configuration configuration)
- where TPixel : struct, IPixel
- {
- var result = new DenseMatrix(colorMatrix.Columns, colorMatrix.Rows);
- Color.ToPixel(configuration, colorMatrix.Span, result.Span);
- return result;
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs b/src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs
deleted file mode 100644
index 91da332a16..0000000000
--- a/src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs
+++ /dev/null
@@ -1,168 +0,0 @@
-// 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
-{
- ///
- /// Gradient Brush with elliptic shape.
- /// The ellipse is defined by a center point,
- /// a point on the longest extension of the ellipse and
- /// the ratio between longest and shortest extension.
- ///
- public sealed class EllipticGradientBrush : GradientBrush
- {
- private readonly PointF center;
-
- private readonly PointF referenceAxisEnd;
-
- private readonly float axisRatio;
-
- ///
- /// The center of the elliptical gradient and 0 for the color stops.
- /// The end point of the reference axis of the ellipse.
- ///
- /// The ratio of the axis widths.
- /// The second axis' is perpendicular to the reference axis and
- /// it's length is the reference axis' length multiplied by this factor.
- ///
- /// Defines how the colors of the gradients are repeated.
- /// the color stops as defined in base class.
- public EllipticGradientBrush(
- PointF center,
- PointF referenceAxisEnd,
- float axisRatio,
- GradientRepetitionMode repetitionMode,
- params ColorStop[] colorStops)
- : base(repetitionMode, colorStops)
- {
- this.center = center;
- this.referenceAxisEnd = referenceAxisEnd;
- this.axisRatio = axisRatio;
- }
-
- ///
- public override BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options) =>
- new RadialGradientBrushApplicator(
- source,
- options,
- this.center,
- this.referenceAxisEnd,
- this.axisRatio,
- this.ColorStops,
- this.RepetitionMode);
-
- ///
- private sealed class RadialGradientBrushApplicator : GradientBrushApplicator
- where TPixel : struct, IPixel
- {
- private readonly PointF center;
-
- private readonly PointF referenceAxisEnd;
-
- private readonly float axisRatio;
-
- private readonly double rotation;
-
- private readonly float referenceRadius;
-
- private readonly float secondRadius;
-
- private readonly float cosRotation;
-
- private readonly float sinRotation;
-
- private readonly float secondRadiusSquared;
-
- private readonly float referenceRadiusSquared;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target image
- /// The options
- /// Center of the ellipse
- /// Point on one angular points of the ellipse.
- ///
- /// Ratio of the axis length's. Used to determine the length of the second axis,
- /// the first is defined by and .
- /// Definition of colors
- /// Defines how the gradient colors are repeated.
- public RadialGradientBrushApplicator(
- ImageFrame target,
- GraphicsOptions options,
- PointF center,
- PointF referenceAxisEnd,
- float axisRatio,
- ColorStop[] colorStops,
- GradientRepetitionMode repetitionMode)
- : base(target, options, colorStops, repetitionMode)
- {
- this.center = center;
- this.referenceAxisEnd = referenceAxisEnd;
- this.axisRatio = axisRatio;
- this.rotation = this.AngleBetween(
- this.center,
- new PointF(this.center.X + 1, this.center.Y),
- this.referenceAxisEnd);
- this.referenceRadius = this.DistanceBetween(this.center, this.referenceAxisEnd);
- this.secondRadius = this.referenceRadius * this.axisRatio;
-
- this.referenceRadiusSquared = this.referenceRadius * this.referenceRadius;
- this.secondRadiusSquared = this.secondRadius * this.secondRadius;
-
- this.sinRotation = (float)Math.Sin(this.rotation);
- this.cosRotation = (float)Math.Cos(this.rotation);
- }
-
- ///
- public override void Dispose()
- {
- }
-
- ///
- protected override float PositionOnGradient(float xt, float yt)
- {
- float x0 = xt - this.center.X;
- float y0 = yt - this.center.Y;
-
- float x = (x0 * this.cosRotation) - (y0 * this.sinRotation);
- float y = (x0 * this.sinRotation) + (y0 * this.cosRotation);
-
- float xSquared = x * x;
- float ySquared = y * y;
-
- var inBoundaryChecker = (xSquared / this.referenceRadiusSquared)
- + (ySquared / this.secondRadiusSquared);
-
- return inBoundaryChecker;
- }
-
- private float AngleBetween(PointF junction, PointF a, PointF b)
- {
- var vA = a - junction;
- var vB = b - junction;
- return MathF.Atan2(vB.Y, vB.X) - MathF.Atan2(vA.Y, vA.X);
- }
-
- private float DistanceBetween(
- PointF p1,
- PointF p2)
- {
- float dX = p1.X - p2.X;
- float dXsquared = dX * dX;
-
- float dY = p1.Y - p2.Y;
- float dYsquared = dY * dY;
- return MathF.Sqrt(dXsquared + dYsquared);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs
deleted file mode 100644
index 7660e72255..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawBezierExtensions.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of Bezier paths to the type.
- ///
- public static class DrawBezierExtensions
- {
- ///
- /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
-
- ///
- /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
-
- ///
- /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawBeziers(new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawBeziers(options, new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided points as an open Bezier path with the supplied pen
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- params PointF[] points) =>
- source.Draw(options, pen, new Path(new CubicBezierLineSegment(points)));
-
- ///
- /// Draws the provided points as an open Bezier path with the supplied pen
- ///
- /// The image this method extends.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawBeziers(
- this IImageProcessingContext source,
- IPen pen,
- params PointF[] points) =>
- source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs
deleted file mode 100644
index 981cf1bef4..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawImageExtensions.cs
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Processing.Processors.Drawing;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of images to the type.
- ///
- public static class DrawImageExtensions
- {
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- float opacity) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- Point.Empty,
- GraphicsOptions.Default.ColorBlendingMode,
- GraphicsOptions.Default.AlphaCompositionMode,
- opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The blending mode.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- PixelColorBlendingMode colorBlending,
- float opacity) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- Point.Empty,
- colorBlending,
- GraphicsOptions.Default.AlphaCompositionMode,
- opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The color blending mode.
- /// The alpha composition mode.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- PixelColorBlendingMode colorBlending,
- PixelAlphaCompositionMode alphaComposition,
- float opacity) =>
- source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The options, including the blending type and blending amount.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- GraphicsOptions options) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- Point.Empty,
- options.ColorBlendingMode,
- options.AlphaCompositionMode,
- options.BlendPercentage));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The location to draw the blended image.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- Point location,
- float opacity) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- location,
- GraphicsOptions.Default.ColorBlendingMode,
- GraphicsOptions.Default.AlphaCompositionMode,
- opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The location to draw the blended image.
- /// The color blending to apply.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- Point location,
- PixelColorBlendingMode colorBlending,
- float opacity) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- location,
- colorBlending,
- GraphicsOptions.Default.AlphaCompositionMode,
- opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The location to draw the blended image.
- /// The color blending to apply.
- /// The alpha composition mode.
- /// The opacity of the image to blend. Must be between 0 and 1.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- Point location,
- PixelColorBlendingMode colorBlending,
- PixelAlphaCompositionMode alphaComposition,
- float opacity) =>
- source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, alphaComposition, opacity));
-
- ///
- /// Draws the given image together with the current one by blending their pixels.
- ///
- /// The image this method extends.
- /// The image to blend with the currently processing image.
- /// The location to draw the blended image.
- /// The options containing the blend mode and opacity.
- /// The .
- public static IImageProcessingContext DrawImage(
- this IImageProcessingContext source,
- Image image,
- Point location,
- GraphicsOptions options) =>
- source.ApplyProcessor(
- new DrawImageProcessor(
- image,
- location,
- options.ColorBlendingMode,
- options.AlphaCompositionMode,
- options.BlendPercentage));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs
deleted file mode 100644
index 98e8fdc594..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawLineExtensions.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of lines to the type.
- ///
- public static class DrawLineExtensions
- {
- ///
- /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawLines(new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .>
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawLines(options, new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided Points as an open Linear path with the supplied pen
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- params PointF[] points) =>
- source.Draw(options, pen, new Path(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as an open Linear path with the supplied pen
- ///
- /// The image this method extends.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawLines(
- this IImageProcessingContext source,
- IPen pen,
- params PointF[] points) =>
- source.Draw(pen, new Path(new LinearLineSegment(points)));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs
deleted file mode 100644
index a68b69a444..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathCollectionExtensions.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of collections of polygon outlines to the type.
- ///
- public static class DrawPathCollectionExtensions
- {
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The paths.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- IPathCollection paths)
- {
- foreach (IPath path in paths)
- {
- source.Draw(options, pen, path);
- }
-
- return source;
- }
-
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The image this method extends.
- /// The pen.
- /// The paths.
- /// The .
- public static IImageProcessingContext
- Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) =>
- source.Draw(GraphicsOptions.Default, pen, paths);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The shapes.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- IPathCollection paths) =>
- source.Draw(options, new Pen(brush, thickness), paths);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The paths.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- IPathCollection paths) =>
- source.Draw(new Pen(brush, thickness), paths);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The paths.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- IPathCollection paths) =>
- source.Draw(options, new SolidBrush(color), thickness, paths);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The paths.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- IPathCollection paths) =>
- source.Draw(new SolidBrush(color), thickness, paths);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs
deleted file mode 100644
index dfe30f6a3c..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPathExtensions.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of polygon outlines to the type.
- ///
- public static class DrawPathExtensions
- {
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The path.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- IPath path) =>
- source.Fill(options, pen.StrokeFill, new ShapePath(path, pen));
-
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The image this method extends.
- /// The pen.
- /// The path.
- /// The .
- public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) =>
- source.Draw(GraphicsOptions.Default, pen, path);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- IPath path) =>
- source.Draw(options, new Pen(brush, thickness), path);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The path.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- IPath path) =>
- source.Draw(new Pen(brush, thickness), path);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The path.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- IPath path) =>
- source.Draw(options, new SolidBrush(color), thickness, path);
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The path.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- IPath path) =>
- source.Draw(new SolidBrush(color), thickness, path);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs
deleted file mode 100644
index 86d8e9e2e2..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawPolygonExtensions.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of closed linear polygons to the type.
- ///
- public static class DrawPolygonExtensions
- {
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(options, new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- params PointF[] points) =>
- source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawPolygon(new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- params PointF[] points) =>
- source.DrawPolygon(options, new SolidBrush(color), thickness, points);
-
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
- ///
- /// The image this method extends.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- IPen pen,
- params PointF[] points) =>
- source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The points.
- /// The .
- public static IImageProcessingContext DrawPolygon(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- params PointF[] points) =>
- source.Draw(options, pen, new Polygon(new LinearLineSegment(points)));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs
deleted file mode 100644
index da78ab2ecc..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawRectangleExtensions.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of rectangles to the type.
- ///
- public static class DrawRectangleExtensions
- {
- ///
- /// Draws the outline of the rectangle with the provided pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The pen.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IPen pen,
- RectangleF shape) =>
- source.Draw(options, pen, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
-
- ///
- /// Draws the outline of the rectangle with the provided pen.
- ///
- /// The image this method extends.
- /// The pen.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) =>
- source.Draw(GraphicsOptions.Default, pen, shape);
-
- ///
- /// Draws the outline of the rectangle with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The thickness.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- float thickness,
- RectangleF shape) =>
- source.Draw(options, new Pen(brush, thickness), shape);
-
- ///
- /// Draws the outline of the rectangle with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- IBrush brush,
- float thickness,
- RectangleF shape) =>
- source.Draw(new Pen(brush, thickness), shape);
-
- ///
- /// Draws the outline of the rectangle with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The thickness.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- float thickness,
- RectangleF shape) =>
- source.Draw(options, new SolidBrush(color), thickness, shape);
-
- ///
- /// Draws the outline of the rectangle with the provided brush at the provided thickness.
- ///
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The shape.
- /// The .
- public static IImageProcessingContext Draw(
- this IImageProcessingContext source,
- Color color,
- float thickness,
- RectangleF shape) =>
- source.Draw(new SolidBrush(color), thickness, shape);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs
deleted file mode 100644
index 05cd3a1ae6..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/DrawTextExtensions.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Fonts;
-using SixLabors.ImageSharp.Processing.Processors.Text;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the drawing of text to the type.
- ///
- public static class DrawTextExtensions
- {
- ///
- /// Draws the text onto the the image filled via the brush.
- ///
- /// The image this method extends.
- /// The text.
- /// The font.
- /// The color.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- string text,
- Font font,
- Color color,
- PointF location) =>
- source.DrawText(TextGraphicsOptions.Default, text, font, color, location);
-
- ///
- /// Draws the text onto the the image filled via the brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The text.
- /// The font.
- /// The color.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- TextGraphicsOptions options,
- string text,
- Font font,
- Color color,
- PointF location) =>
- source.DrawText(options, text, font, Brushes.Solid(color), null, location);
-
- ///
- /// Draws the text onto the the image filled via the brush.
- ///
- /// The image this method extends.
- /// The text.
- /// The font.
- /// The brush.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- string text,
- Font font,
- IBrush brush,
- PointF location) =>
- source.DrawText(TextGraphicsOptions.Default, text, font, brush, location);
-
- ///
- /// Draws the text onto the the image filled via the brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The text.
- /// The font.
- /// The brush.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- TextGraphicsOptions options,
- string text,
- Font font,
- IBrush brush,
- PointF location) =>
- source.DrawText(options, text, font, brush, null, location);
-
- ///
- /// Draws the text onto the the image outlined via the pen.
- ///
- /// The image this method extends.
- /// The text.
- /// The font.
- /// The pen.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- string text,
- Font font,
- IPen pen,
- PointF location) =>
- source.DrawText(TextGraphicsOptions.Default, text, font, pen, location);
-
- ///
- /// Draws the text onto the the image outlined via the pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The text.
- /// The font.
- /// The pen.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- TextGraphicsOptions options,
- string text,
- Font font,
- IPen pen,
- PointF location) =>
- source.DrawText(options, text, font, null, pen, location);
-
- ///
- /// Draws the text onto the the image filled via the brush then outlined via the pen.
- ///
- /// The image this method extends.
- /// The text.
- /// The font.
- /// The brush.
- /// The pen.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- string text,
- Font font,
- IBrush brush,
- IPen pen,
- PointF location) =>
- source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location);
-
- ///
- /// Draws the text using the default resolution of 72dpi onto the the image filled via the brush then outlined via the pen.
- ///
- /// The image this method extends.
- /// The options.
- /// The text.
- /// The font.
- /// The brush.
- /// The pen.
- /// The location.
- ///
- /// The .
- ///
- public static IImageProcessingContext DrawText(
- this IImageProcessingContext source,
- TextGraphicsOptions options,
- string text,
- Font font,
- IBrush brush,
- IPen pen,
- PointF location) =>
- source.ApplyProcessor(new DrawTextProcessor(options, text, font, brush, pen, location));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs
deleted file mode 100644
index 5de9c6d4ed..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of polygons with various brushes to the type.
- ///
- public static class FillPathBuilderExtensions
- {
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The graphics options.
- /// The brush.
- /// The shape.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- Action path)
- {
- var pb = new PathBuilder();
- path(pb);
-
- return source.Fill(options, brush, pb.Build());
- }
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The brush.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- IBrush brush,
- Action path) =>
- source.Fill(GraphicsOptions.Default, brush, path);
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- Action path) =>
- source.Fill(options, new SolidBrush(color), path);
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The color.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- Color color,
- Action path) =>
- source.Fill(new SolidBrush(color), path);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs
deleted file mode 100644
index 776e1f7e4e..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathCollectionExtensions.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of collections of polygon outlines to the type.
- ///
- public static class FillPathCollectionExtensions
- {
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The graphics options.
- /// The brush.
- /// The shapes.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- IPathCollection paths)
- {
- foreach (IPath s in paths)
- {
- source.Fill(options, brush, s);
- }
-
- return source;
- }
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The brush.
- /// The paths.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- IBrush brush,
- IPathCollection paths) =>
- source.Fill(GraphicsOptions.Default, brush, paths);
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The paths.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- IPathCollection paths) =>
- source.Fill(options, new SolidBrush(color), paths);
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The color.
- /// The paths.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- Color color,
- IPathCollection paths) =>
- source.Fill(new SolidBrush(color), paths);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs
deleted file mode 100644
index 718016a9e6..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathExtensions.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of polygon outlines to the type.
- ///
- public static class FillPathExtensions
- {
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The graphics options.
- /// The brush.
- /// The shape.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- IPath path) =>
- source.Fill(options, brush, new ShapeRegion(path));
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The image this method extends.
- /// The brush.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) =>
- source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path));
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush..
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- IPath path) =>
- source.Fill(options, new SolidBrush(color), path);
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush..
- ///
- /// The image this method extends.
- /// The color.
- /// The path.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color, IPath path) =>
- source.Fill(new SolidBrush(color), path);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs
deleted file mode 100644
index 9262c8baad..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillPolygonExtensions.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of closed linear polygons to the type.
- ///
- public static class FillPolygonExtensions
- {
- ///
- /// Flood fills the image in the shape of a Linear polygon described by the points
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The points.
- /// The .
- public static IImageProcessingContext FillPolygon(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- params PointF[] points) =>
- source.Fill(options, brush, new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Flood fills the image in the shape of a Linear polygon described by the points
- ///
- /// The image this method extends.
- /// The brush.
- /// The points.
- /// The .
- public static IImageProcessingContext FillPolygon(
- this IImageProcessingContext source,
- IBrush brush,
- params PointF[] points) =>
- source.Fill(brush, new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Flood fills the image in the shape of a Linear polygon described by the points
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The points.
- /// The .
- public static IImageProcessingContext FillPolygon(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- params PointF[] points) =>
- source.Fill(options, new SolidBrush(color), new Polygon(new LinearLineSegment(points)));
-
- ///
- /// Flood fills the image in the shape of a Linear polygon described by the points
- ///
- /// The image this method extends.
- /// The color.
- /// The points.
- /// The .
- public static IImageProcessingContext FillPolygon(
- this IImageProcessingContext source,
- Color color,
- params PointF[] points) =>
- source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs
deleted file mode 100644
index cfe37deb2c..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillRectangleExtensions.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of rectangles to the type.
- ///
- public static class FillRectangleExtensions
- {
- ///
- /// Flood fills the image in the shape of the provided rectangle with the specified brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The brush.
- /// The shape.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- RectangleF shape) =>
- source.Fill(options, brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
-
- ///
- /// Flood fills the image in the shape of the provided rectangle with the specified brush.
- ///
- /// The image this method extends.
- /// The brush.
- /// The shape.
- /// The .
- public static IImageProcessingContext
- Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape) =>
- source.Fill(brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
-
- ///
- /// Flood fills the image in the shape of the provided rectangle with the specified brush.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The shape.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- RectangleF shape) =>
- source.Fill(options, new SolidBrush(color), shape);
-
- ///
- /// Flood fills the image in the shape of the provided rectangle with the specified brush.
- ///
- /// The image this method extends.
- /// The color.
- /// The shape.
- /// The .
- public static IImageProcessingContext
- Fill(this IImageProcessingContext source, Color color, RectangleF shape) =>
- source.Fill(new SolidBrush(color), shape);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs
deleted file mode 100644
index 294e575140..0000000000
--- a/src/ImageSharp.Drawing/Processing/Extensions/FillRegionExtensions.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.ImageSharp.Processing.Processors.Drawing;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Adds extensions that allow the filling of regions with various brushes to the type.
- ///
- public static class FillRegionExtensions
- {
- ///
- /// Flood fills the image with the specified brush.
- ///
- /// The image this method extends.
- /// The details how to fill the region of interest.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) =>
- source.Fill(GraphicsOptions.Default, brush);
-
- ///
- /// Flood fills the image with the specified color.
- ///
- /// The image this method extends.
- /// The color.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color) =>
- source.Fill(new SolidBrush(color));
-
- ///
- /// Flood fills the image with in the region with the specified brush.
- ///
- /// The image this method extends.
- /// The brush.
- /// The region.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) =>
- source.Fill(GraphicsOptions.Default, brush, region);
-
- ///
- /// Flood fills the image with in the region with the specified color.
- ///
- /// The image this method extends.
- /// The options.
- /// The color.
- /// The region.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- Color color,
- Region region) =>
- source.Fill(options, new SolidBrush(color), region);
-
- ///
- /// Flood fills the image with in the region with the specified color.
- ///
- /// The image this method extends.
- /// The color.
- /// The region.
- /// The .
- public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color, Region region) =>
- source.Fill(new SolidBrush(color), region);
-
- ///
- /// Flood fills the image with in the region with the specified brush.
- ///
- /// The image this method extends.
- /// The graphics options.
- /// The brush.
- /// The region.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush,
- Region region) =>
- source.ApplyProcessor(new FillRegionProcessor(brush, region, options));
-
- ///
- /// Flood fills the image with the specified brush.
- ///
- /// The image this method extends.
- /// The graphics options.
- /// The details how to fill the region of interest.
- /// The .
- public static IImageProcessingContext Fill(
- this IImageProcessingContext source,
- GraphicsOptions options,
- IBrush brush) =>
- source.ApplyProcessor(new FillProcessor(brush, options));
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/GradientBrush.cs b/src/ImageSharp.Drawing/Processing/GradientBrush.cs
deleted file mode 100644
index 9826748c46..0000000000
--- a/src/ImageSharp.Drawing/Processing/GradientBrush.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Numerics;
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.PixelFormats.PixelBlenders;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Base class for Gradient brushes
- ///
- public abstract class GradientBrush : IBrush
- {
- ///
- /// Defines how the colors are repeated beyond the interval [0..1]
- /// The gradient colors.
- protected GradientBrush(
- GradientRepetitionMode repetitionMode,
- params ColorStop[] colorStops)
- {
- this.RepetitionMode = repetitionMode;
- this.ColorStops = colorStops;
- }
-
- ///
- /// Gets how the colors are repeated beyond the interval [0..1].
- ///
- protected GradientRepetitionMode RepetitionMode { get; }
-
- ///
- /// Gets the list of color stops for this gradient.
- ///
- protected ColorStop[] ColorStops { get; }
-
- ///
- public abstract BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel;
-
- ///
- /// Base class for gradient brush applicators
- ///
- internal abstract class GradientBrushApplicator : BrushApplicator
- where TPixel : struct, IPixel
- {
- private static readonly TPixel Transparent = Color.Transparent.ToPixel();
-
- private readonly ColorStop[] colorStops;
-
- private readonly GradientRepetitionMode repetitionMode;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- /// The options.
- /// An array of color stops sorted by their position.
- /// Defines if and how the gradient should be repeated.
- protected GradientBrushApplicator(
- ImageFrame target,
- GraphicsOptions options,
- ColorStop[] colorStops,
- GradientRepetitionMode repetitionMode)
- : base(target, options)
- {
- this.colorStops = colorStops; // TODO: requires colorStops to be sorted by position - should that be checked?
- this.repetitionMode = repetitionMode;
- }
-
- ///
- /// Base implementation of the indexer for gradients
- /// (follows the facade pattern, using abstract methods)
- ///
- /// X coordinate of the Pixel.
- /// Y coordinate of the Pixel.
- internal override TPixel this[int x, int y]
- {
- get
- {
- float positionOnCompleteGradient = this.PositionOnGradient(x + 0.5f, y + 0.5f);
-
- switch (this.repetitionMode)
- {
- case GradientRepetitionMode.None:
- // do nothing. The following could be done, but is not necessary:
- // onLocalGradient = Math.Min(0, Math.Max(1, onLocalGradient));
- break;
- case GradientRepetitionMode.Repeat:
- positionOnCompleteGradient = positionOnCompleteGradient % 1;
- break;
- case GradientRepetitionMode.Reflect:
- positionOnCompleteGradient = positionOnCompleteGradient % 2;
- if (positionOnCompleteGradient > 1)
- {
- positionOnCompleteGradient = 2 - positionOnCompleteGradient;
- }
-
- break;
- case GradientRepetitionMode.DontFill:
- if (positionOnCompleteGradient > 1 || positionOnCompleteGradient < 0)
- {
- return Transparent;
- }
-
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
-
- (ColorStop from, ColorStop to) = this.GetGradientSegment(positionOnCompleteGradient);
-
- if (from.Color.Equals(to.Color))
- {
- return from.Color.ToPixel();
- }
- else
- {
- var fromAsVector = from.Color.ToVector4();
- var toAsVector = to.Color.ToVector4();
- float onLocalGradient = (positionOnCompleteGradient - from.Ratio) / (to.Ratio - from.Ratio);
-
- // TODO: this should be changeble for different gradienting functions
- Vector4 result = PorterDuffFunctions.NormalSrcOver(
- fromAsVector,
- toAsVector,
- onLocalGradient);
-
- TPixel resultColor = default;
- resultColor.FromVector4(result);
- return resultColor;
- }
- }
- }
-
- ///
- /// calculates the position on the gradient for a given point.
- /// This method is abstract as it's content depends on the shape of the gradient.
- ///
- /// The x coordinate of the point
- /// The y coordinate of the point
- ///
- /// The position the given point has on the gradient.
- /// The position is not bound to the [0..1] interval.
- /// Values outside of that interval may be treated differently,
- /// e.g. for the enum.
- ///
- protected abstract float PositionOnGradient(float x, float y);
-
- private (ColorStop from, ColorStop to) GetGradientSegment(
- float positionOnCompleteGradient)
- {
- ColorStop localGradientFrom = this.colorStops[0];
- ColorStop localGradientTo = default;
-
- // TODO: ensure colorStops has at least 2 items (technically 1 would be okay, but that's no gradient)
- foreach (ColorStop colorStop in this.colorStops)
- {
- localGradientTo = colorStop;
-
- if (colorStop.Ratio > positionOnCompleteGradient)
- {
- // we're done here, so break it!
- break;
- }
-
- localGradientFrom = localGradientTo;
- }
-
- return (localGradientFrom, localGradientTo);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs b/src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs
deleted file mode 100644
index 6aed8a030c..0000000000
--- a/src/ImageSharp.Drawing/Processing/GradientRepetitionMode.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Modes to repeat a gradient.
- ///
- public enum GradientRepetitionMode
- {
- ///
- /// don't repeat, keep the color of start and end beyond those points stable.
- ///
- None,
-
- ///
- /// Repeat the gradient.
- /// If it's a black-white gradient, with Repeat it will be Black->{gray}->White|Black->{gray}->White|...
- ///
- Repeat,
-
- ///
- /// Reflect the gradient.
- /// Similar to , but each other repetition uses inverse order of s.
- /// Used on a Black-White gradient, Reflect leads to Black->{gray}->White->{gray}->White...
- ///
- Reflect,
-
- ///
- /// With DontFill a gradient does not touch any pixel beyond it's borders.
- /// For the this is beyond the orthogonal through start and end,
- /// TODO For the cref="PolygonalGradientBrush" it's outside the polygon,
- /// For and it's beyond 1.0.
- ///
- DontFill
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/IBrush.cs b/src/ImageSharp.Drawing/Processing/IBrush.cs
deleted file mode 100644
index 0cd2e20fda..0000000000
--- a/src/ImageSharp.Drawing/Processing/IBrush.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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
-{
- ///
- /// Brush represents a logical configuration of a brush which can be used to source pixel colors
- ///
- ///
- /// A brush is a simple class that will return an that will perform the
- /// logic for retrieving pixel values for specific locations.
- ///
- public interface IBrush
- {
- ///
- /// Creates the applicator for this brush.
- ///
- /// The pixel type.
- /// The source image.
- /// The region the brush will be applied to.
- /// The graphic options
- ///
- /// The brush applicator for this brush
- ///
- ///
- /// The when being applied to things like shapes would usually be the
- /// bounding box of the shape not necessarily the bounds of the whole image
- ///
- BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel;
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/IPen.cs b/src/ImageSharp.Drawing/Processing/IPen.cs
deleted file mode 100644
index 0efcfc108c..0000000000
--- a/src/ImageSharp.Drawing/Processing/IPen.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Interface representing the pattern and size of the stroke to apply with a Pen.
- ///
- public interface IPen
- {
- ///
- /// Gets the stroke fill.
- ///
- IBrush StrokeFill { get; }
-
- ///
- /// Gets the width to apply to the stroke
- ///
- float StrokeWidth { get; }
-
- ///
- /// Gets the stoke pattern.
- ///
- ReadOnlySpan StrokePattern { get; }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/ImageBrush.cs b/src/ImageSharp.Drawing/Processing/ImageBrush.cs
deleted file mode 100644
index 8485ddfd09..0000000000
--- a/src/ImageSharp.Drawing/Processing/ImageBrush.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides an implementation of an image brush for painting images within areas.
- ///
- public class ImageBrush : IBrush
- {
- ///
- /// The image to paint.
- ///
- private readonly Image image;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The image.
- public ImageBrush(Image image)
- {
- this.image = image;
- }
-
- ///
- public BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel
- {
- if (this.image is Image specificImage)
- {
- return new ImageBrushApplicator(source, specificImage, region, options, false);
- }
-
- specificImage = this.image.CloneAs();
-
- return new ImageBrushApplicator(source, specificImage, region, options, true);
- }
-
- ///
- /// The image brush applicator.
- ///
- private class ImageBrushApplicator : BrushApplicator
- where TPixel : struct, IPixel
- {
- private ImageFrame sourceFrame;
-
- private Image sourceImage;
-
- private readonly bool shouldDisposeImage;
-
- ///
- /// The y-length.
- ///
- private readonly int yLength;
-
- ///
- /// The x-length.
- ///
- private readonly int xLength;
-
- ///
- /// The Y offset.
- ///
- private readonly int offsetY;
-
- ///
- /// The X offset.
- ///
- private readonly int offsetX;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target image.
- /// The image.
- /// The region.
- /// The options
- /// Whether to dispose the image on disposal of the applicator.
- public ImageBrushApplicator(
- ImageFrame target,
- Image image,
- RectangleF region,
- GraphicsOptions options,
- bool shouldDisposeImage)
- : base(target, options)
- {
- this.sourceImage = image;
- this.sourceFrame = image.Frames.RootFrame;
- this.shouldDisposeImage = shouldDisposeImage;
- this.xLength = image.Width;
- this.yLength = image.Height;
- this.offsetY = (int)MathF.Max(MathF.Floor(region.Top), 0);
- this.offsetX = (int)MathF.Max(MathF.Floor(region.Left), 0);
- }
-
- ///
- /// Gets the color for a single pixel.
- ///
- /// The x.
- /// The y.
- ///
- /// The color
- ///
- internal override TPixel this[int x, int y]
- {
- get
- {
- int srcX = (x - this.offsetX) % this.xLength;
- int srcY = (y - this.offsetY) % this.yLength;
- return this.sourceFrame[srcX, srcY];
- }
- }
-
- ///
- public override void Dispose()
- {
- if (this.shouldDisposeImage)
- {
- this.sourceImage?.Dispose();
- this.sourceImage = null;
- this.sourceFrame = null;
- }
- }
-
- ///
- internal override void Apply(Span scanline, int x, int y)
- {
- // Create a span for colors
- using (IMemoryOwner amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length))
- using (IMemoryOwner overlay = this.Target.MemoryAllocator.Allocate(scanline.Length))
- {
- Span amountSpan = amountBuffer.GetSpan();
- Span overlaySpan = overlay.GetSpan();
-
- int sourceY = (y - this.offsetY) % this.yLength;
- int offsetX = x - this.offsetX;
- Span sourceRow = this.sourceFrame.GetPixelRowSpan(sourceY);
-
- for (int i = 0; i < scanline.Length; i++)
- {
- amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
-
- int sourceX = (i + offsetX) % this.xLength;
- TPixel pixel = sourceRow[sourceX];
- overlaySpan[i] = pixel;
- }
-
- Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(
- this.sourceFrame.Configuration,
- destinationRow,
- destinationRow,
- overlaySpan,
- amountSpan);
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs b/src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs
deleted file mode 100644
index bb99eeb26a..0000000000
--- a/src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-// 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
-{
- ///
- /// Provides an implementation of a brush for painting linear gradients within areas.
- /// Supported right now:
- /// - a set of colors in relative distances to each other.
- ///
- public sealed class LinearGradientBrush : GradientBrush
- {
- private readonly PointF p1;
-
- private readonly PointF p2;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Start point
- /// End point
- /// defines how colors are repeated.
- ///
- public LinearGradientBrush(
- PointF p1,
- PointF p2,
- GradientRepetitionMode repetitionMode,
- params ColorStop[] colorStops)
- : base(repetitionMode, colorStops)
- {
- this.p1 = p1;
- this.p2 = p2;
- }
-
- ///
- public override BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options) =>
- new LinearGradientBrushApplicator(
- source,
- this.p1,
- this.p2,
- this.ColorStops,
- this.RepetitionMode,
- options);
-
- ///
- /// The linear gradient brush applicator.
- ///
- private sealed class LinearGradientBrushApplicator : GradientBrushApplicator
- where TPixel : struct, IPixel
- {
- private readonly PointF start;
-
- private readonly PointF end;
-
- ///
- /// the vector along the gradient, x component
- ///
- private readonly float alongX;
-
- ///
- /// the vector along the gradient, y component
- ///
- private readonly float alongY;
-
- ///
- /// the vector perpendicular to the gradient, y component
- ///
- private readonly float acrossY;
-
- ///
- /// the vector perpendicular to the gradient, x component
- ///
- private readonly float acrossX;
-
- ///
- /// the result of ^2 + ^2
- ///
- private readonly float alongsSquared;
-
- ///
- /// the length of the defined gradient (between source and end)
- ///
- private readonly float length;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The source
- /// start point of the gradient
- /// end point of the gradient
- /// tuple list of colors and their respective position between 0 and 1 on the line
- /// defines how the gradient colors are repeated.
- /// the graphics options
- public LinearGradientBrushApplicator(
- ImageFrame source,
- PointF start,
- PointF end,
- ColorStop[] colorStops,
- GradientRepetitionMode repetitionMode,
- GraphicsOptions options)
- : base(source, options, colorStops, repetitionMode)
- {
- this.start = start;
- this.end = end;
-
- // the along vector:
- this.alongX = this.end.X - this.start.X;
- this.alongY = this.end.Y - this.start.Y;
-
- // the cross vector:
- this.acrossX = this.alongY;
- this.acrossY = -this.alongX;
-
- // some helpers:
- this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY);
- this.length = MathF.Sqrt(this.alongsSquared);
- }
-
- protected override float PositionOnGradient(float x, float y)
- {
- if (this.acrossX == 0)
- {
- return (x - this.start.X) / (this.end.X - this.start.X);
- }
- else if (this.acrossY == 0)
- {
- return (y - this.start.Y) / (this.end.Y - this.start.Y);
- }
- else
- {
- float deltaX = x - this.start.X;
- float deltaY = y - this.start.Y;
- float k = ((this.alongY * deltaX) - (this.alongX * deltaY)) / this.alongsSquared;
-
- // point on the line:
- float x4 = x - (k * this.alongY);
- float y4 = y + (k * this.alongX);
-
- // get distance from (x4,y4) to start
- float distance = MathF.Sqrt(MathF.Pow(x4 - this.start.X, 2) + MathF.Pow(y4 - this.start.Y, 2));
-
- // get and return ratio
- float ratio = distance / this.length;
- return ratio;
- }
- }
-
- public override void Dispose()
- {
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/PathGradientBrush.cs b/src/ImageSharp.Drawing/Processing/PathGradientBrush.cs
deleted file mode 100644
index 7315dc5a3e..0000000000
--- a/src/ImageSharp.Drawing/Processing/PathGradientBrush.cs
+++ /dev/null
@@ -1,287 +0,0 @@
-// 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 SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides an implementation of a brush for painting gradients between multiple color positions in 2D coordinates.
- /// It works similarly with the class in System.Drawing.Drawing2D of the same name.
- ///
- public sealed class PathGradientBrush : IBrush
- {
- private readonly IList edges;
-
- private readonly Color centerColor;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Points that constitute a polygon that represents the gradient area.
- /// Array of colors that correspond to each point in the polygon.
- /// Color at the center of the gradient area to which the other colors converge.
- public PathGradientBrush(PointF[] points, Color[] colors, Color centerColor)
- {
- if (points == null)
- {
- throw new ArgumentNullException(nameof(points));
- }
-
- if (points.Length < 3)
- {
- throw new ArgumentOutOfRangeException(
- nameof(points),
- "There must be at least 3 lines to construct a path gradient brush.");
- }
-
- if (colors == null)
- {
- throw new ArgumentNullException(nameof(colors));
- }
-
- if (!colors.Any())
- {
- throw new ArgumentOutOfRangeException(
- nameof(colors),
- "One or more color is needed to construct a path gradient brush.");
- }
-
- int size = points.Length;
-
- var lines = new ILineSegment[size];
-
- for (int i = 0; i < size; i++)
- {
- lines[i] = new LinearLineSegment(points[i % size], points[(i + 1) % size]);
- }
-
- this.centerColor = centerColor;
-
- Color ColorAt(int index) => colors[index % colors.Length];
-
- this.edges = lines.Select(s => new Path(s))
- .Select((path, i) => new Edge(path, ColorAt(i), ColorAt(i + 1))).ToList();
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Points that constitute a polygon that represents the gradient area.
- /// Array of colors that correspond to each point in the polygon.
- public PathGradientBrush(PointF[] points, Color[] colors)
- : this(points, colors, CalculateCenterColor(colors))
- {
- }
-
- ///
- public BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel
- {
- return new PathGradientBrushApplicator(source, this.edges, this.centerColor, options);
- }
-
- private static Color CalculateCenterColor(Color[] colors)
- {
- if (colors == null)
- {
- throw new ArgumentNullException(nameof(colors));
- }
-
- if (!colors.Any())
- {
- throw new ArgumentOutOfRangeException(
- nameof(colors),
- "One or more color is needed to construct a path gradient brush.");
- }
-
- return new Color(colors.Select(c => c.ToVector4()).Aggregate((p1, p2) => p1 + p2) / colors.Length);
- }
-
- private static float DistanceBetween(PointF p1, PointF p2) => ((Vector2)(p2 - p1)).Length();
-
- private struct Intersection
- {
- public Intersection(PointF point, float distance)
- {
- this.Point = point;
- this.Distance = distance;
- }
-
- public PointF Point { get; }
-
- public float Distance { get; }
- }
-
- ///
- /// An edge of the polygon that represents the gradient area.
- ///
- private class Edge
- {
- private readonly Path path;
-
- private readonly float length;
-
- private readonly PointF[] buffer;
-
- public Edge(Path path, Color startColor, Color endColor)
- {
- this.path = path;
-
- Vector2[] points = path.LineSegments.SelectMany(s => s.Flatten()).Select(p => (Vector2)p).ToArray();
-
- this.Start = points.First();
- this.StartColor = startColor.ToVector4();
-
- this.End = points.Last();
- this.EndColor = endColor.ToVector4();
-
- this.length = DistanceBetween(this.End, this.Start);
- this.buffer = new PointF[this.path.MaxIntersections];
- }
-
- public PointF Start { get; }
-
- public Vector4 StartColor { get; }
-
- public PointF End { get; }
-
- public Vector4 EndColor { get; }
-
- public Intersection? FindIntersection(PointF start, PointF end)
- {
- int intersections = this.path.FindIntersections(start, end, this.buffer);
-
- if (intersections == 0)
- {
- return null;
- }
-
- return this.buffer.Take(intersections)
- .Select(p => new Intersection(point: p, distance: ((Vector2)(p - start)).LengthSquared()))
- .Aggregate((min, current) => min.Distance > current.Distance ? current : min);
- }
-
- public Vector4 ColorAt(float distance)
- {
- float ratio = this.length > 0 ? distance / this.length : 0;
-
- return Vector4.Lerp(this.StartColor, this.EndColor, ratio);
- }
-
- public Vector4 ColorAt(PointF point) => this.ColorAt(DistanceBetween(point, this.Start));
- }
-
- ///
- /// The path gradient brush applicator.
- ///
- private class PathGradientBrushApplicator : BrushApplicator
- where TPixel : struct, IPixel
- {
- private readonly PointF center;
-
- private readonly Vector4 centerColor;
-
- private readonly float maxDistance;
-
- private readonly IList edges;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The source image.
- /// Edges of the polygon.
- /// Color at the center of the gradient area to which the other colors converge.
- /// The options.
- public PathGradientBrushApplicator(
- ImageFrame source,
- IList edges,
- Color centerColor,
- GraphicsOptions options)
- : base(source, options)
- {
- this.edges = edges;
-
- PointF[] points = edges.Select(s => s.Start).ToArray();
-
- this.center = points.Aggregate((p1, p2) => p1 + p2) / edges.Count;
- this.centerColor = centerColor.ToVector4();
-
- this.maxDistance = points.Select(p => (Vector2)(p - this.center)).Select(d => d.Length()).Max();
- }
-
- ///
- internal override TPixel this[int x, int y]
- {
- get
- {
- var point = new PointF(x, y);
-
- if (point == this.center)
- {
- return new Color(this.centerColor).ToPixel();
- }
-
- Vector2 direction = Vector2.Normalize(point - this.center);
-
- PointF end = point + (PointF)(direction * this.maxDistance);
-
- (Edge edge, Intersection? info) = this.FindIntersection(point, end);
-
- if (!info.HasValue)
- {
- return Color.Transparent.ToPixel();
- }
-
- PointF intersection = info.Value.Point;
-
- Vector4 edgeColor = edge.ColorAt(intersection);
-
- float length = DistanceBetween(intersection, this.center);
- float ratio = length > 0 ? DistanceBetween(intersection, point) / length : 0;
-
- Vector4 color = Vector4.Lerp(edgeColor, this.centerColor, ratio);
-
- return new Color(color).ToPixel();
- }
- }
-
- private (Edge edge, Intersection? info) FindIntersection(PointF start, PointF end)
- {
- (Edge edge, Intersection? info) closest = default;
-
- foreach (Edge edge in this.edges)
- {
- Intersection? intersection = edge.FindIntersection(start, end);
-
- if (!intersection.HasValue)
- {
- continue;
- }
-
- if (closest.info == null || closest.info.Value.Distance > intersection.Value.Distance)
- {
- closest = (edge, intersection);
- }
- }
-
- return closest;
- }
-
- ///
- public override void Dispose()
- {
- }
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/PatternBrush.cs b/src/ImageSharp.Drawing/Processing/PatternBrush.cs
deleted file mode 100644
index 1999af8a39..0000000000
--- a/src/ImageSharp.Drawing/Processing/PatternBrush.cs
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-using System.Numerics;
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.Memory;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides an implementation of a pattern brush for painting patterns.
- ///
- ///
- /// The patterns that are used to create a custom pattern brush are made up of a repeating matrix of flags,
- /// where each flag denotes whether to draw the foreground color or the background color.
- /// so to create a new bool[,] with your flags
- ///
- /// For example if you wanted to create a diagonal line that repeat every 4 pixels you would use a pattern like so
- /// 1000
- /// 0100
- /// 0010
- /// 0001
- ///
- ///
- /// or you want a horizontal stripe which is 3 pixels apart you would use a pattern like
- /// 1
- /// 0
- /// 0
- ///
- ///
- public class PatternBrush : IBrush
- {
- ///
- /// The pattern.
- ///
- private readonly DenseMatrix pattern;
- private readonly DenseMatrix patternVector;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color of the fore.
- /// Color of the back.
- /// The pattern.
- public PatternBrush(Color foreColor, Color backColor, bool[,] pattern)
- : this(foreColor, backColor, new DenseMatrix(pattern))
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color of the fore.
- /// Color of the back.
- /// The pattern.
- internal PatternBrush(Color foreColor, Color backColor, in DenseMatrix pattern)
- {
- var foreColorVector = foreColor.ToVector4();
- var backColorVector = backColor.ToVector4();
- this.pattern = new DenseMatrix(pattern.Columns, pattern.Rows);
- this.patternVector = new DenseMatrix(pattern.Columns, pattern.Rows);
- for (int i = 0; i < pattern.Data.Length; i++)
- {
- if (pattern.Data[i])
- {
- this.pattern.Data[i] = foreColor;
- this.patternVector.Data[i] = foreColorVector;
- }
- else
- {
- this.pattern.Data[i] = backColor;
- this.patternVector.Data[i] = backColorVector;
- }
- }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- internal PatternBrush(PatternBrush brush)
- {
- this.pattern = brush.pattern;
- this.patternVector = brush.patternVector;
- }
-
- ///
- public BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel =>
- new PatternBrushApplicator(
- source,
- this.pattern.ToPixelMatrix(source.Configuration),
- options);
-
- ///
- /// The pattern brush applicator.
- ///
- private class PatternBrushApplicator : BrushApplicator
- where TPixel : struct, IPixel
- {
- ///
- /// The pattern.
- ///
- private readonly DenseMatrix pattern;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The source image.
- /// The pattern.
- /// The options
- public PatternBrushApplicator(ImageFrame source, in DenseMatrix pattern, GraphicsOptions options)
- : base(source, options)
- {
- this.pattern = pattern;
- }
-
- ///
- /// Gets the color for a single pixel.
- /// #
- /// The x.
- /// The y.
- ///
- /// The Color.
- ///
- internal override TPixel this[int x, int y]
- {
- get
- {
- x = x % this.pattern.Columns;
- y = y % this.pattern.Rows;
-
- // 2d array index at row/column
- return this.pattern[y, x];
- }
- }
-
- ///
- public override void Dispose()
- {
- // noop
- }
-
- ///
- internal override void Apply(Span scanline, int x, int y)
- {
- int patternY = y % this.pattern.Rows;
- MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
-
- using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length))
- using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length))
- {
- Span amountSpan = amountBuffer.GetSpan();
- Span overlaySpan = overlay.GetSpan();
-
- for (int i = 0; i < scanline.Length; i++)
- {
- amountSpan[i] = (scanline[i] * this.Options.BlendPercentage).Clamp(0, 1);
-
- int patternX = (x + i) % this.pattern.Columns;
- overlaySpan[i] = this.pattern[patternY, patternX];
- }
-
- Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(
- this.Target.Configuration,
- destinationRow,
- destinationRow,
- overlaySpan,
- amountSpan);
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Pen.cs b/src/ImageSharp.Drawing/Processing/Pen.cs
deleted file mode 100644
index ebad687d5a..0000000000
--- a/src/ImageSharp.Drawing/Processing/Pen.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides a pen that can apply a pattern to a line with a set brush and thickness
- ///
- ///
- /// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
- /// converted into a pattern that is 3.5 times longer that the width with 3 sections
- /// section 1 will be width long (making a square) and will be filled by the brush
- /// section 2 will be width * 2 long and will be empty
- /// section 3 will be width/2 long and will be filled
- /// the the pattern will immediately repeat without gap.
- ///
- public class Pen : IPen
- {
- private readonly float[] pattern;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The color.
- /// The width.
- /// The pattern.
- public Pen(Color color, float width, float[] pattern)
- : this(new SolidBrush(color), width, pattern)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- /// The width.
- /// The pattern.
- public Pen(IBrush brush, float width, float[] pattern)
- {
- this.StrokeFill = brush;
- this.StrokeWidth = width;
- this.pattern = pattern;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The color.
- /// The width.
- public Pen(Color color, float width)
- : this(new SolidBrush(color), width)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- /// The width.
- public Pen(IBrush brush, float width)
- : this(brush, width, Pens.EmptyPattern)
- {
- }
-
- ///
- public IBrush StrokeFill { get; }
-
- ///
- public float StrokeWidth { get; }
-
- ///
- public ReadOnlySpan StrokePattern => this.pattern;
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Pens.cs b/src/ImageSharp.Drawing/Processing/Pens.cs
deleted file mode 100644
index e60b5b6c7c..0000000000
--- a/src/ImageSharp.Drawing/Processing/Pens.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Contains a collection of common Pen styles
- ///
- public static class Pens
- {
- private static readonly float[] DashDotPattern = { 3f, 1f, 1f, 1f };
- private static readonly float[] DashDotDotPattern = { 3f, 1f, 1f, 1f, 1f, 1f };
- private static readonly float[] DottedPattern = { 1f, 1f };
- private static readonly float[] DashedPattern = { 3f, 1f };
- internal static readonly float[] EmptyPattern = new float[0];
-
- ///
- /// Create a solid pen with out any drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Solid(Color color, float width) => new Pen(color, width);
-
- ///
- /// Create a solid pen with out any drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Solid(IBrush brush, float width) => new Pen(brush, width);
-
- ///
- /// Create a pen with a 'Dash' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Dash(Color color, float width) => new Pen(color, width, DashedPattern);
-
- ///
- /// Create a pen with a 'Dash' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Dash(IBrush brush, float width) => new Pen(brush, width, DashedPattern);
-
- ///
- /// Create a pen with a 'Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Dot(Color color, float width) => new Pen(color, width, DottedPattern);
-
- ///
- /// Create a pen with a 'Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Dot(IBrush brush, float width) => new Pen(brush, width, DottedPattern);
-
- ///
- /// Create a pen with a 'Dash Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen DashDot(Color color, float width) => new Pen(color, width, DashDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen DashDot(IBrush brush, float width) => new Pen(brush, width, DashDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen DashDotDot(Color color, float width) => new Pen(color, width, DashDotDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen DashDotDot(IBrush brush, float width) => new Pen(brush, width, DashDotDotPattern);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
deleted file mode 100644
index e217fd9a6c..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Combines two images together by blending the pixels.
- ///
- public class DrawImageProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The image to blend.
- /// The location to draw the blended image.
- /// The blending mode to use when drawing the image.
- /// The Alpha blending mode to use when drawing the image.
- /// The opacity of the image to blend.
- public DrawImageProcessor(
- Image image,
- Point location,
- PixelColorBlendingMode colorBlendingMode,
- PixelAlphaCompositionMode alphaCompositionMode,
- float opacity)
- {
- this.Image = image;
- this.Location = location;
- this.ColorBlendingMode = colorBlendingMode;
- this.AlphaCompositionMode = alphaCompositionMode;
- this.Opacity = opacity;
- }
-
- ///
- /// Gets the image to blend.
- ///
- public Image Image { get; }
-
- ///
- /// Gets the location to draw the blended image.
- ///
- public Point Location { get; }
-
- ///
- /// Gets the blending mode to use when drawing the image.
- ///
- public PixelColorBlendingMode ColorBlendingMode { get; }
-
- ///
- /// Gets the Alpha blending mode to use when drawing the image.
- ///
- public PixelAlphaCompositionMode AlphaCompositionMode { get; }
-
- ///
- /// Gets the opacity of the image to blend.
- ///
- public float Opacity { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor(Image source, Rectangle sourceRectangle)
- where TPixelBg : struct, IPixel
- {
- var visitor = new ProcessorFactoryVisitor(this, source, sourceRectangle);
- this.Image.AcceptVisitor(visitor);
- return visitor.Result;
- }
-
- private class ProcessorFactoryVisitor : IImageVisitor
- where TPixelBg : struct, IPixel
- {
- private readonly DrawImageProcessor definition;
- private readonly Image source;
- private readonly Rectangle sourceRectangle;
-
- public ProcessorFactoryVisitor(DrawImageProcessor definition, Image source, Rectangle sourceRectangle)
- {
- this.definition = definition;
- this.source = source;
- this.sourceRectangle = sourceRectangle;
- }
-
- public IImageProcessor Result { get; private set; }
-
- public void Visit(Image image)
- where TPixelFg : struct, IPixel
- {
- this.Result = new DrawImageProcessor(
- image,
- this.source,
- this.sourceRectangle,
- this.definition.Location,
- this.definition.ColorBlendingMode,
- this.definition.AlphaCompositionMode,
- this.definition.Opacity);
- }
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
deleted file mode 100644
index 76082136c7..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.ParallelUtils;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Combines two images together by blending the pixels.
- ///
- /// The pixel format of destination image.
- /// The pixel format of source image.
- internal class DrawImageProcessor : ImageProcessor
- where TPixelBg : struct, IPixel
- where TPixelFg : struct, IPixel
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The foreground to blend with the currently processing image.
- /// The source for the current processor instance.
- /// The source area to process for the current processor instance.
- /// The location to draw the blended image.
- /// The blending mode to use when drawing the image.
- /// The Alpha blending mode to use when drawing the image.
- /// The opacity of the image to blend. Must be between 0 and 1.
- public DrawImageProcessor(
- Image image,
- Image source,
- Rectangle sourceRectangle,
- Point location,
- PixelColorBlendingMode colorBlendingMode,
- PixelAlphaCompositionMode alphaCompositionMode,
- float opacity)
- : base(source, sourceRectangle)
- {
- Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
-
- this.Image = image;
- this.Opacity = opacity;
- this.Blender = PixelOperations.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
- this.Location = location;
- }
-
- ///
- /// Gets the image to blend
- ///
- public Image Image { get; }
-
- ///
- /// Gets the opacity of the image to blend
- ///
- public float Opacity { get; }
-
- ///
- /// Gets the pixel blender
- ///
- public PixelBlender Blender { get; }
-
- ///
- /// Gets the location to draw the blended image
- ///
- public Point Location { get; }
-
- ///
- protected override void OnFrameApply(ImageFrame source)
- {
- Rectangle sourceRectangle = this.SourceRectangle;
- Configuration configuration = this.Configuration;
-
- Image targetImage = this.Image;
- PixelBlender blender = this.Blender;
- int locationY = this.Location.Y;
-
- // Align start/end positions.
- Rectangle bounds = targetImage.Bounds();
-
- int minX = Math.Max(this.Location.X, sourceRectangle.X);
- int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Right);
- int targetX = minX - this.Location.X;
-
- int minY = Math.Max(this.Location.Y, sourceRectangle.Y);
- int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom);
-
- int width = maxX - minX;
-
- var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
-
- // Not a valid operation because rectangle does not overlap with this image.
- if (workingRect.Width <= 0 || workingRect.Height <= 0)
- {
- throw new ImageProcessingException(
- "Cannot draw image because the source image does not overlap the target image.");
- }
-
- ParallelHelper.IterateRows(
- workingRect,
- configuration,
- rows =>
- {
- for (int y = rows.Min; y < rows.Max; y++)
- {
- Span background = source.GetPixelRowSpan(y).Slice(minX, width);
- Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
- blender.Blend(configuration, background, background, foreground, this.Opacity);
- }
- });
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
deleted file mode 100644
index 1d3cf35576..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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.Processors.Drawing
-{
- ///
- /// Defines a processor to fill an with the given
- /// using blending defined by the given .
- ///
- public class FillProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush to use for filling.
- /// The defining how to blend the brush pixels over the image pixels.
- public FillProcessor(IBrush brush, GraphicsOptions options)
- {
- this.Brush = brush;
- this.Options = options;
- }
-
- ///
- /// Gets the used for filling the destination image.
- ///
- public IBrush Brush { get; }
-
- ///
- /// Gets the defining how to blend the brush pixels over the image pixels.
- ///
- public GraphicsOptions Options { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor(Image source, Rectangle sourceRectangle)
- where TPixel : struct, IPixel
- {
- return new FillProcessor(this, source, sourceRectangle);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs
deleted file mode 100644
index a7c22f6d7b..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.ParallelUtils;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Using the brush as a source of pixels colors blends the brush color with source.
- ///
- /// The pixel format.
- internal class FillProcessor : ImageProcessor
- where TPixel : struct, IPixel
- {
- private readonly FillProcessor definition;
-
- public FillProcessor(FillProcessor definition, Image source, Rectangle sourceRectangle)
- : base(source, sourceRectangle)
- {
- this.definition = definition;
- }
-
- ///
- protected override void OnFrameApply(ImageFrame source)
- {
- Rectangle sourceRectangle = this.SourceRectangle;
- Configuration configuration = this.Configuration;
- int startX = sourceRectangle.X;
- int endX = sourceRectangle.Right;
- int startY = sourceRectangle.Y;
- int endY = sourceRectangle.Bottom;
-
- // 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);
-
- int width = maxX - minX;
-
- var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
-
- IBrush brush = this.definition.Brush;
- GraphicsOptions options = this.definition.Options;
-
- // If there's no reason for blending, then avoid it.
- if (this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush))
- {
- ParallelExecutionSettings parallelSettings = configuration.GetParallelSettings().MultiplyMinimumPixelsPerTask(4);
-
- TPixel colorPixel = solidBrush.Color.ToPixel();
-
- ParallelHelper.IterateRows(
- workingRect,
- parallelSettings,
- rows =>
- {
- for (int y = rows.Min; y < rows.Max; y++)
- {
- source.GetPixelRowSpan(y).Slice(minX, width).Fill(colorPixel);
- }
- });
- }
- else
- {
- // Reset offset if necessary.
- if (minX > 0)
- {
- startX = 0;
- }
-
- if (minY > 0)
- {
- startY = 0;
- }
-
- using (IMemoryOwner amount = source.MemoryAllocator.Allocate(width))
- using (BrushApplicator applicator = brush.CreateApplicator(
- source,
- sourceRectangle,
- options))
- {
- amount.GetSpan().Fill(1f);
-
- ParallelHelper.IterateRows(
- workingRect,
- configuration,
- rows =>
- {
- for (int y = rows.Min; y < rows.Max; y++)
- {
- int offsetY = y - startY;
- int offsetX = minX - startX;
-
- applicator.Apply(amount.GetSpan(), offsetX, offsetY);
- }
- });
- }
- }
- }
-
- private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
- {
- solidBrush = this.definition.Brush as SolidBrush;
-
- if (solidBrush == null)
- {
- return false;
- }
-
- return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
deleted file mode 100644
index 2318f3168b..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Defines a processor to fill pixels withing a given
- /// with the given and blending defined by the given .
- ///
- public class FillRegionProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The details how to fill the region of interest.
- /// The region of interest to be filled.
- /// The configuration options.
- public FillRegionProcessor(IBrush brush, Region region, GraphicsOptions options)
- {
- this.Region = region;
- this.Brush = brush;
- this.Options = options;
- }
-
- ///
- /// Gets the used for filling the destination image.
- ///
- public IBrush Brush { get; }
-
- ///
- /// Gets the region that this processor applies to.
- ///
- public Region Region { get; }
-
- ///
- /// Gets the defining how to blend the brush pixels over the image pixels.
- ///
- public GraphicsOptions Options { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor(Image source, Rectangle sourceRectangle)
- where TPixel : struct, IPixel
- {
- return new FillRegionProcessor(this, source, sourceRectangle);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs
deleted file mode 100644
index 45d5015ae0..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Primitives;
-using SixLabors.ImageSharp.Utils;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Using a brush and a shape fills shape with contents of brush the
- ///
- /// The type of the color.
- ///
- internal class FillRegionProcessor : ImageProcessor
- where TPixel : struct, IPixel
- {
- private readonly FillRegionProcessor definition;
-
- public FillRegionProcessor(FillRegionProcessor definition, Image source, Rectangle sourceRectangle)
- : base(source, sourceRectangle)
- {
- this.definition = definition;
- }
-
- ///
- protected override void OnFrameApply(ImageFrame source)
- {
- Configuration configuration = this.Configuration;
- GraphicsOptions options = this.definition.Options;
- IBrush brush = this.definition.Brush;
- Region region = this.definition.Region;
- Rectangle rect = region.Bounds;
-
- // Align start/end positions.
- int minX = Math.Max(0, rect.Left);
- int maxX = Math.Min(source.Width, rect.Right);
- int minY = Math.Max(0, rect.Top);
- int maxY = Math.Min(source.Height, rect.Bottom);
- if (minX >= maxX)
- {
- return; // no effect inside image;
- }
-
- if (minY >= maxY)
- {
- return; // no effect inside image;
- }
-
- int maxIntersections = region.MaxIntersections;
- float subpixelCount = 4;
-
- // we need to offset the pixel grid to account for when we outline a path.
- // basically if the line is [1,2] => [3,2] then when outlining at 1 we end up with a region of [0.5,1.5],[1.5, 1.5],[3.5,2.5],[2.5,2.5]
- // and this can cause missed fills when not using antialiasing.so we offset the pixel grid by 0.5 in the x & y direction thus causing the#
- // region to align with the pixel grid.
- float offset = 0.5f;
- if (options.Antialias)
- {
- offset = 0f; // we are antialiasing skip offsetting as real antialiasing should take care of offset.
- subpixelCount = options.AntialiasSubpixelDepth;
- if (subpixelCount < 4)
- {
- subpixelCount = 4;
- }
- }
-
- using (BrushApplicator applicator = brush.CreateApplicator(source, rect, options))
- {
- int scanlineWidth = maxX - minX;
- using (IMemoryOwner bBuffer = source.MemoryAllocator.Allocate(maxIntersections))
- using (IMemoryOwner bScanline = source.MemoryAllocator.Allocate(scanlineWidth))
- {
- bool scanlineDirty = true;
- float subpixelFraction = 1f / subpixelCount;
- float subpixelFractionPoint = subpixelFraction / subpixelCount;
-
- Span buffer = bBuffer.GetSpan();
- Span scanline = bScanline.GetSpan();
-
- bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush);
- TPixel solidBrushColor = isSolidBrushWithoutBlending ? solidBrush.Color.ToPixel() : default;
-
- for (int y = minY; y < maxY; y++)
- {
- if (scanlineDirty)
- {
- scanline.Clear();
- scanlineDirty = false;
- }
-
- float yPlusOne = y + 1;
- for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
- {
- int pointsFound = region.Scan(subPixel + offset, buffer, configuration);
- if (pointsFound == 0)
- {
- // nothing on this line, skip
- continue;
- }
-
- QuickSort.Sort(buffer.Slice(0, pointsFound));
-
- for (int point = 0; point < pointsFound && point < buffer.Length - 1; point += 2)
- {
- // points will be paired up
- float scanStart = buffer[point] - minX;
- float scanEnd = buffer[point + 1] - minX;
- int startX = (int)MathF.Floor(scanStart + offset);
- int endX = (int)MathF.Floor(scanEnd + offset);
-
- if (startX >= 0 && startX < scanline.Length)
- {
- for (float x = scanStart; x < startX + 1; x += subpixelFraction)
- {
- scanline[startX] += subpixelFractionPoint;
- scanlineDirty = true;
- }
- }
-
- if (endX >= 0 && endX < scanline.Length)
- {
- for (float x = endX; x < scanEnd; x += subpixelFraction)
- {
- scanline[endX] += subpixelFractionPoint;
- scanlineDirty = true;
- }
- }
-
- int nextX = startX + 1;
- endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge
- nextX = Math.Max(nextX, 0);
- for (int x = nextX; x < endX; x++)
- {
- scanline[x] += subpixelFraction;
- scanlineDirty = true;
- }
- }
- }
-
- if (scanlineDirty)
- {
- if (!options.Antialias)
- {
- bool hasOnes = false;
- bool hasZeros = false;
- for (int x = 0; x < scanlineWidth; x++)
- {
- if (scanline[x] >= 0.5)
- {
- scanline[x] = 1;
- hasOnes = true;
- }
- else
- {
- scanline[x] = 0;
- hasZeros = true;
- }
- }
-
- if (isSolidBrushWithoutBlending && hasOnes != hasZeros)
- {
- if (hasOnes)
- {
- source.GetPixelRowSpan(y).Slice(minX, scanlineWidth).Fill(solidBrushColor);
- }
-
- continue;
- }
- }
-
- applicator.Apply(scanline, minX, y);
- }
- }
- }
- }
- }
-
- private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
- {
- solidBrush = this.definition.Brush as SolidBrush;
-
- if (solidBrush == null)
- {
- return false;
- }
-
- return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
deleted file mode 100644
index 775cf55abf..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-
-using SixLabors.Fonts;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Text
-{
- ///
- /// Defines a processor to draw text on an .
- ///
- public class DrawTextProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The options
- /// The text we want to render
- /// The font we want to render with
- /// The brush to source pixel colors from.
- /// The pen to outline text with.
- /// The location on the image to start drawing the text from.
- public DrawTextProcessor(TextGraphicsOptions options, string text, Font font, IBrush brush, IPen pen, PointF location)
- {
- Guard.NotNull(text, nameof(text));
- Guard.NotNull(font, nameof(font));
-
- if (brush is null && pen is null)
- {
- throw new ArgumentNullException($"Expected a {nameof(brush)} or {nameof(pen)}. Both were null");
- }
-
- this.Options = options;
- this.Text = text;
- this.Font = font;
- this.Location = location;
- this.Brush = brush;
- this.Pen = pen;
- }
-
- ///
- /// Gets the brush used to fill the glyphs.
- ///
- public IBrush Brush { get; }
-
- ///
- /// Gets the defining blending modes and text-specific drawing settings.
- ///
- public TextGraphicsOptions Options { get; }
-
- ///
- /// Gets the text to draw.
- ///
- public string Text { get; }
-
- ///
- /// Gets the pen used for outlining the text, if Null then we will not outline
- ///
- public IPen Pen { get; }
-
- ///
- /// Gets the font used to render the text.
- ///
- public Font Font { get; }
-
- ///
- /// Gets the location to draw the text at.
- ///
- public PointF Location { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor(Image source, Rectangle sourceRectangle)
- where TPixel : struct, IPixel
- {
- return new DrawTextProcessor(this, source, sourceRectangle);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs
deleted file mode 100644
index ea042635dd..0000000000
--- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs
+++ /dev/null
@@ -1,453 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-using System.Collections.Generic;
-
-using SixLabors.Fonts;
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Utils;
-using SixLabors.Memory;
-using SixLabors.Primitives;
-using SixLabors.Shapes;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Text
-{
- ///
- /// Using the brush as a source of pixels colors blends the brush color with source.
- ///
- /// The pixel format.
- internal class DrawTextProcessor : ImageProcessor
- where TPixel : struct, IPixel
- {
- private CachingGlyphRenderer textRenderer;
-
- private readonly DrawTextProcessor definition;
-
- public DrawTextProcessor(DrawTextProcessor definition, Image source, Rectangle sourceRectangle)
- : base(source, sourceRectangle)
- {
- this.definition = definition;
- }
-
- private TextGraphicsOptions Options => this.definition.Options;
-
- private Font Font => this.definition.Font;
-
- private PointF Location => this.definition.Location;
-
- private string Text => this.definition.Text;
-
- private IPen Pen => this.definition.Pen;
-
- private IBrush Brush => this.definition.Brush;
-
- protected override void BeforeImageApply()
- {
- base.BeforeImageApply();
-
- // do everything at the image level as we are delegating the processing down to other processors
- var style = new RendererOptions(this.Font, this.Options.DpiX, this.Options.DpiY, this.Location)
- {
- ApplyKerning = this.Options.ApplyKerning,
- TabWidth = this.Options.TabWidth,
- WrappingWidth = this.Options.WrapTextWidth,
- HorizontalAlignment = this.Options.HorizontalAlignment,
- VerticalAlignment = this.Options.VerticalAlignment
- };
-
- this.textRenderer = new CachingGlyphRenderer(this.Source.GetMemoryAllocator(), this.Text.Length, this.Pen, this.Brush != null);
- this.textRenderer.Options = (GraphicsOptions)this.Options;
- var renderer = new TextRenderer(this.textRenderer);
- renderer.RenderText(this.Text, style);
- }
-
- protected override void AfterImageApply()
- {
- base.AfterImageApply();
- this.textRenderer?.Dispose();
- this.textRenderer = null;
- }
-
- ///
- protected override void OnFrameApply(ImageFrame source)
- {
- // this is a no-op as we have processes all as an image, we should be able to pass out of before email apply a skip frames outcome
- Draw(this.textRenderer.FillOperations, this.Brush);
- Draw(this.textRenderer.OutlineOperations, this.Pen?.StrokeFill);
-
- void Draw(List operations, IBrush brush)
- {
- if (operations?.Count > 0)
- {
- using (BrushApplicator app = brush.CreateApplicator(source, this.SourceRectangle, this.textRenderer.Options))
- {
- foreach (DrawingOperation operation in operations)
- {
- Buffer2D buffer = operation.Map;
- int startY = operation.Location.Y;
- int startX = operation.Location.X;
- int offsetSpan = 0;
- if (startX < 0)
- {
- offsetSpan = -startX;
- startX = 0;
- }
-
- if (startX >= source.Width)
- {
- continue;
- }
-
- int firstRow = 0;
- if (startY < 0)
- {
- firstRow = -startY;
- }
-
- int maxHeight = source.Height - startY;
- int end = Math.Min(operation.Map.Height, maxHeight);
-
- for (int row = firstRow; row < end; row++)
- {
- int y = startY + row;
- Span span = buffer.GetRowSpan(row).Slice(offsetSpan);
- app.Apply(span, startX, y);
- }
- }
- }
- }
- }
- }
-
- private struct DrawingOperation
- {
- public Buffer2D Map { get; set; }
-
- public Point Location { get; set; }
- }
-
- private class CachingGlyphRenderer : IGlyphRenderer, IDisposable
- {
- // just enough accuracy to allow for 1/8 pixel differences which
- // later are accumulated while rendering, but do not grow into full pixel offsets
- // The value 8 is benchmarked to:
- // - Provide a good accuracy (smaller than 0.2% image difference compared to the non-caching variant)
- // - Cache hit ratio above 60%
- private const float AccuracyMultiple = 8;
-
- private readonly PathBuilder builder;
-
- private Point currentRenderPosition;
- private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams;
- private readonly int offset;
- private PointF currentPoint;
-
- private readonly Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>
- glyphData = new Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>();
-
- private readonly bool renderOutline;
- private readonly bool renderFill;
- private bool rasterizationRequired;
-
- public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, IPen pen, bool renderFill)
- {
- this.MemoryAllocator = memoryAllocator;
- this.currentRenderPosition = default;
- this.Pen = pen;
- this.renderFill = renderFill;
- this.renderOutline = pen != null;
- this.offset = 2;
- if (this.renderFill)
- {
- this.FillOperations = new List(size);
- }
-
- if (this.renderOutline)
- {
- this.offset = (int)MathF.Ceiling((pen.StrokeWidth * 2) + 2);
- this.OutlineOperations = new List(size);
- }
-
- this.builder = new PathBuilder();
- }
-
- public List FillOperations { get; }
-
- public List OutlineOperations { get; }
-
- public MemoryAllocator MemoryAllocator { get; internal set; }
-
- public IPen Pen { get; internal set; }
-
- public GraphicsOptions Options { get; internal set; }
-
- public void BeginFigure()
- {
- this.builder.StartFigure();
- }
-
- public bool BeginGlyph(RectangleF bounds, GlyphRendererParameters parameters)
- {
- this.currentRenderPosition = Point.Truncate(bounds.Location);
- PointF subPixelOffset = bounds.Location - this.currentRenderPosition;
-
- subPixelOffset.X = MathF.Round(subPixelOffset.X * AccuracyMultiple) / AccuracyMultiple;
- subPixelOffset.Y = MathF.Round(subPixelOffset.Y * AccuracyMultiple) / AccuracyMultiple;
-
- // we have offset our rendering origin a little bit down to prevent edge cropping, move the draw origin up to compensate
- this.currentRenderPosition = new Point(this.currentRenderPosition.X - this.offset, this.currentRenderPosition.Y - this.offset);
- this.currentGlyphRenderParams = (parameters, subPixelOffset);
-
- if (this.glyphData.ContainsKey(this.currentGlyphRenderParams))
- {
- // we have already drawn the glyph vectors skip trying again
- this.rasterizationRequired = false;
- return false;
- }
-
- // we check to see if we have a render cache and if we do then we render else
- this.builder.Clear();
-
- // ensure all glyphs render around [zero, zero] so offset negative root positions so when we draw the glyph we can offset it back
- this.builder.SetOrigin(new PointF(-(int)bounds.X + this.offset, -(int)bounds.Y + this.offset));
-
- this.rasterizationRequired = true;
- return true;
- }
-
- public void BeginText(RectangleF bounds)
- {
- // not concerned about this one
- this.OutlineOperations?.Clear();
- this.FillOperations?.Clear();
- }
-
- public void CubicBezierTo(PointF secondControlPoint, PointF thirdControlPoint, PointF point)
- {
- this.builder.AddBezier(this.currentPoint, secondControlPoint, thirdControlPoint, point);
- this.currentPoint = point;
- }
-
- public void Dispose()
- {
- foreach (KeyValuePair<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData> kv in this.glyphData)
- {
- kv.Value.Dispose();
- }
-
- this.glyphData.Clear();
- }
-
- public void EndFigure()
- {
- this.builder.CloseFigure();
- }
-
- public void EndGlyph()
- {
- GlyphRenderData renderData = default;
-
- // has the glyph been rendered already?
- if (this.rasterizationRequired)
- {
- IPath path = this.builder.Build();
-
- if (this.renderFill)
- {
- renderData.FillMap = this.Render(path);
- }
-
- if (this.renderOutline)
- {
- if (this.Pen.StrokePattern.Length == 0)
- {
- path = path.GenerateOutline(this.Pen.StrokeWidth);
- }
- else
- {
- path = path.GenerateOutline(this.Pen.StrokeWidth, this.Pen.StrokePattern);
- }
-
- renderData.OutlineMap = this.Render(path);
- }
-
- this.glyphData[this.currentGlyphRenderParams] = renderData;
- }
- else
- {
- renderData = this.glyphData[this.currentGlyphRenderParams];
- }
-
- if (this.renderFill)
- {
- this.FillOperations.Add(new DrawingOperation
- {
- Location = this.currentRenderPosition,
- Map = renderData.FillMap
- });
- }
-
- if (this.renderOutline)
- {
- this.OutlineOperations.Add(new DrawingOperation
- {
- Location = this.currentRenderPosition,
- Map = renderData.OutlineMap
- });
- }
- }
-
- private Buffer2D Render(IPath path)
- {
- Size size = Rectangle.Ceiling(path.Bounds).Size;
- size = new Size(size.Width + (this.offset * 2), size.Height + (this.offset * 2));
-
- float subpixelCount = 4;
- float offset = 0.5f;
- if (this.Options.Antialias)
- {
- offset = 0f; // we are antialiasing skip offsetting as real antialiasing should take care of offset.
- subpixelCount = this.Options.AntialiasSubpixelDepth;
- if (subpixelCount < 4)
- {
- subpixelCount = 4;
- }
- }
-
- // take the path inside the path builder, scan thing and generate a Buffer2d representing the glyph and cache it.
- Buffer2D fullBuffer = this.MemoryAllocator.Allocate2D(size.Width + 1, size.Height + 1, AllocationOptions.Clean);
-
- using (IMemoryOwner bufferBacking = this.MemoryAllocator.Allocate(path.MaxIntersections))
- using (IMemoryOwner rowIntersectionBuffer = this.MemoryAllocator.Allocate(size.Width))
- {
- float subpixelFraction = 1f / subpixelCount;
- float subpixelFractionPoint = subpixelFraction / subpixelCount;
-
- for (int y = 0; y <= size.Height; y++)
- {
- Span scanline = fullBuffer.GetRowSpan(y);
- bool scanlineDirty = false;
- float yPlusOne = y + 1;
-
- for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
- {
- var start = new PointF(path.Bounds.Left - 1, subPixel);
- var end = new PointF(path.Bounds.Right + 1, subPixel);
- Span intersectionSpan = rowIntersectionBuffer.GetSpan();
- Span buffer = bufferBacking.GetSpan();
- int pointsFound = path.FindIntersections(start, end, intersectionSpan);
-
- if (pointsFound == 0)
- {
- // nothing on this line skip
- continue;
- }
-
- for (int i = 0; i < pointsFound && i < intersectionSpan.Length; i++)
- {
- buffer[i] = intersectionSpan[i].X;
- }
-
- QuickSort.Sort(buffer.Slice(0, pointsFound));
-
- for (int point = 0; point < pointsFound; point += 2)
- {
- // points will be paired up
- float scanStart = buffer[point];
- float scanEnd = buffer[point + 1];
- int startX = (int)MathF.Floor(scanStart + offset);
- int endX = (int)MathF.Floor(scanEnd + offset);
-
- if (startX >= 0 && startX < scanline.Length)
- {
- for (float x = scanStart; x < startX + 1; x += subpixelFraction)
- {
- scanline[startX] += subpixelFractionPoint;
- scanlineDirty = true;
- }
- }
-
- if (endX >= 0 && endX < scanline.Length)
- {
- for (float x = endX; x < scanEnd; x += subpixelFraction)
- {
- scanline[endX] += subpixelFractionPoint;
- scanlineDirty = true;
- }
- }
-
- int nextX = startX + 1;
- endX = Math.Min(endX, scanline.Length); // reduce to end to the right edge
- nextX = Math.Max(nextX, 0);
- for (int x = nextX; x < endX; x++)
- {
- scanline[x] += subpixelFraction;
- scanlineDirty = true;
- }
- }
- }
-
- if (scanlineDirty)
- {
- if (!this.Options.Antialias)
- {
- for (int x = 0; x < size.Width; x++)
- {
- if (scanline[x] >= 0.5)
- {
- scanline[x] = 1;
- }
- else
- {
- scanline[x] = 0;
- }
- }
- }
- }
- }
- }
-
- return fullBuffer;
- }
-
- public void EndText()
- {
- }
-
- public void LineTo(PointF point)
- {
- this.builder.AddLine(this.currentPoint, point);
- this.currentPoint = point;
- }
-
- public void MoveTo(PointF point)
- {
- this.builder.StartFigure();
- this.currentPoint = point;
- }
-
- public void QuadraticBezierTo(PointF secondControlPoint, PointF point)
- {
- this.builder.AddBezier(this.currentPoint, secondControlPoint, point);
- this.currentPoint = point;
- }
-
- private struct GlyphRenderData : IDisposable
- {
- public Buffer2D FillMap;
-
- public Buffer2D OutlineMap;
-
- public void Dispose()
- {
- this.FillMap?.Dispose();
- this.OutlineMap?.Dispose();
- }
- }
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs b/src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs
deleted file mode 100644
index f4d2dd81f4..0000000000
--- a/src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-// 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
-{
- ///
- /// A Circular Gradient Brush, defined by center point and radius.
- ///
- public sealed class RadialGradientBrush : GradientBrush
- {
- private readonly PointF center;
-
- private readonly float radius;
-
- ///
- /// The center of the circular gradient and 0 for the color stops.
- /// The radius of the circular gradient and 1 for the color stops.
- /// Defines how the colors in the gradient are repeated.
- /// the color stops as defined in base class.
- public RadialGradientBrush(
- PointF center,
- float radius,
- GradientRepetitionMode repetitionMode,
- params ColorStop[] colorStops)
- : base(repetitionMode, colorStops)
- {
- this.center = center;
- this.radius = radius;
- }
-
- ///
- public override BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options) =>
- new RadialGradientBrushApplicator(
- source,
- options,
- this.center,
- this.radius,
- this.ColorStops,
- this.RepetitionMode);
-
- ///
- private sealed class RadialGradientBrushApplicator : GradientBrushApplicator
- where TPixel : struct, IPixel
- {
- private readonly PointF center;
-
- private readonly float radius;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target image
- /// The options.
- /// Center point of the gradient.
- /// Radius of the gradient.
- /// Definition of colors.
- /// How the colors are repeated beyond the first gradient.
- public RadialGradientBrushApplicator(
- ImageFrame target,
- GraphicsOptions options,
- PointF center,
- float radius,
- ColorStop[] colorStops,
- GradientRepetitionMode repetitionMode)
- : base(target, options, colorStops, repetitionMode)
- {
- this.center = center;
- this.radius = radius;
- }
-
- ///
- public override void Dispose()
- {
- }
-
- ///
- /// As this is a circular gradient, the position on the gradient is based on
- /// the distance of the point to the center.
- ///
- /// The X coordinate of the target pixel.
- /// The Y coordinate of the target pixel.
- /// the position on the color gradient.
- protected override float PositionOnGradient(float x, float y)
- {
- float distance = MathF.Sqrt(MathF.Pow(this.center.X - x, 2) + MathF.Pow(this.center.Y - y, 2));
- return distance / this.radius;
- }
-
- internal override void Apply(Span scanline, int x, int y)
- {
- // TODO: each row is symmetric across center, so we can calculate half of it and mirror it to improve performance.
- base.Apply(scanline, x, y);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush.cs
deleted file mode 100644
index fca95be327..0000000000
--- a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-using System.Numerics;
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Memory;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides an implementation of a brush that can recolor an image
- ///
- public class RecolorBrush : IBrush
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color of the source.
- /// Color of the target.
- /// The threshold as a value between 0 and 1.
- public RecolorBrush(Color sourceColor, Color targetColor, float threshold)
- {
- this.SourceColor = sourceColor;
- this.Threshold = threshold;
- this.TargetColor = targetColor;
- }
-
- ///
- /// Gets the threshold.
- ///
- public float Threshold { get; }
-
- ///
- /// Gets the source color.
- ///
- ///
- /// The color of the source.
- ///
- public Color SourceColor { get; }
-
- ///
- /// Gets the target color.
- ///
- public Color TargetColor { get; }
-
- ///
- public BrushApplicator CreateApplicator(
- ImageFrame source,
- RectangleF region,
- GraphicsOptions options)
- where TPixel : struct, IPixel
- {
- return new RecolorBrushApplicator(
- source,
- this.SourceColor.ToPixel(),
- this.TargetColor.ToPixel(),
- this.Threshold,
- options);
- }
-
- ///
- /// The recolor brush applicator.
- ///
- private class RecolorBrushApplicator : BrushApplicator
- where TPixel : struct, IPixel
- {
- ///
- /// The source color.
- ///
- private readonly Vector4 sourceColor;
-
- ///
- /// The target color.
- ///
- private readonly Vector4 targetColor;
-
- ///
- /// The threshold.
- ///
- private readonly float threshold;
-
- private readonly TPixel targetColorPixel;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The source image.
- /// Color of the source.
- /// Color of the target.
- /// The threshold .
- /// The options
- public RecolorBrushApplicator(ImageFrame source, TPixel sourceColor, TPixel targetColor, float threshold, GraphicsOptions options)
- : base(source, options)
- {
- this.sourceColor = sourceColor.ToVector4();
- this.targetColor = targetColor.ToVector4();
- this.targetColorPixel = targetColor;
-
- // Lets hack a min max extremes for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
- var maxColor = default(TPixel);
- maxColor.FromVector4(new Vector4(float.MaxValue));
- var minColor = default(TPixel);
- minColor.FromVector4(new Vector4(float.MinValue));
- this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
- }
-
- ///
- /// Gets the color for a single pixel.
- ///
- /// The x.
- /// The y.
- ///
- /// The color
- ///
- internal override TPixel this[int x, int y]
- {
- get
- {
- // Offset the requested pixel by the value in the rectangle (the shapes position)
- TPixel result = this.Target[x, y];
- var background = result.ToVector4();
- float distance = Vector4.DistanceSquared(background, this.sourceColor);
- if (distance <= this.threshold)
- {
- float lerpAmount = (this.threshold - distance) / this.threshold;
- return this.Blender.Blend(
- result,
- this.targetColorPixel,
- lerpAmount);
- }
-
- return result;
- }
- }
-
- ///
- public override void Dispose()
- {
- }
-
- ///
- internal override void Apply(Span scanline, int x, int y)
- {
- MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
-
- using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length))
- using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length))
- {
- Span amountSpan = amountBuffer.GetSpan();
- Span overlaySpan = overlay.GetSpan();
-
- for (int i = 0; i < scanline.Length; i++)
- {
- amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
-
- int offsetX = x + i;
-
- // No doubt this one can be optimized further but I can't imagine its
- // actually being used and can probably be removed/internalized for now
- overlaySpan[i] = this[offsetX, y];
- }
-
- Span destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
- this.Blender.Blend(
- this.Target.Configuration,
- destinationRow,
- destinationRow,
- overlaySpan,
- amountSpan);
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/SolidBrush.cs b/src/ImageSharp.Drawing/Processing/SolidBrush.cs
deleted file mode 100644
index c62566f6b7..0000000000
--- a/src/ImageSharp.Drawing/Processing/SolidBrush.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Memory;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Provides an implementation of a solid brush for painting solid color areas.
- ///
- public class SolidBrush : IBrush
- {
- ///
- /// The color to paint.
- ///
- private readonly Color color;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The color.
- public SolidBrush(Color color)
- {
- this.color = color;
- }
-
- ///
- /// Gets the color.
- ///
- ///
- /// The color.
- ///
- public Color Color => this.color;
-
- ///
- public BrushApplicator CreateApplicator(ImageFrame source, RectangleF region, GraphicsOptions options)
- where TPixel : struct, IPixel
- {
- return new SolidBrushApplicator(source, this.color.ToPixel(), options);
- }
-
- ///
- /// The solid brush applicator.
- ///
- private class SolidBrushApplicator : BrushApplicator