mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
1202 changed files with 36543 additions and 19712 deletions
@ -0,0 +1,4 @@ |
|||
[submodule "tests/Images/External"] |
|||
path = tests/Images/External |
|||
url = https://github.com/SixLabors/Imagesharp.Tests.Images.git |
|||
branch = master |
|||
@ -1,13 +0,0 @@ |
|||
Copyright 2012 James South |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
@ -1,14 +0,0 @@ |
|||
<SolutionConfiguration> |
|||
<FileVersion>1</FileVersion> |
|||
<InferProjectReferencesUsingAssemblyNames>false</InferProjectReferencesUsingAssemblyNames> |
|||
<AllowParallelTestExecution>false</AllowParallelTestExecution> |
|||
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves> |
|||
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit> |
|||
<FrameworkUtilisationTypeForGallio>UseStaticAnalysis</FrameworkUtilisationTypeForGallio> |
|||
<FrameworkUtilisationTypeForMSpec>UseStaticAnalysis</FrameworkUtilisationTypeForMSpec> |
|||
<FrameworkUtilisationTypeForMSTest>UseStaticAnalysis</FrameworkUtilisationTypeForMSTest> |
|||
<FrameworkUtilisationTypeForXUnit2>UseDynamicAnalysis</FrameworkUtilisationTypeForXUnit2> |
|||
<NCrunchCacheStoragePath /> |
|||
<MetricsExclusionList> |
|||
</MetricsExclusionList> |
|||
</SolutionConfiguration> |
|||
@ -0,0 +1,201 @@ |
|||
Apache License |
|||
Version 2.0, January 2004 |
|||
http://www.apache.org/licenses/ |
|||
|
|||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
|||
|
|||
1. Definitions. |
|||
|
|||
"License" shall mean the terms and conditions for use, reproduction, |
|||
and distribution as defined by Sections 1 through 9 of this document. |
|||
|
|||
"Licensor" shall mean the copyright owner or entity authorized by |
|||
the copyright owner that is granting the License. |
|||
|
|||
"Legal Entity" shall mean the union of the acting entity and all |
|||
other entities that control, are controlled by, or are under common |
|||
control with that entity. For the purposes of this definition, |
|||
"control" means (i) the power, direct or indirect, to cause the |
|||
direction or management of such entity, whether by contract or |
|||
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
|||
outstanding shares, or (iii) beneficial ownership of such entity. |
|||
|
|||
"You" (or "Your") shall mean an individual or Legal Entity |
|||
exercising permissions granted by this License. |
|||
|
|||
"Source" form shall mean the preferred form for making modifications, |
|||
including but not limited to software source code, documentation |
|||
source, and configuration files. |
|||
|
|||
"Object" form shall mean any form resulting from mechanical |
|||
transformation or translation of a Source form, including but |
|||
not limited to compiled object code, generated documentation, |
|||
and conversions to other media types. |
|||
|
|||
"Work" shall mean the work of authorship, whether in Source or |
|||
Object form, made available under the License, as indicated by a |
|||
copyright notice that is included in or attached to the work |
|||
(an example is provided in the Appendix below). |
|||
|
|||
"Derivative Works" shall mean any work, whether in Source or Object |
|||
form, that is based on (or derived from) the Work and for which the |
|||
editorial revisions, annotations, elaborations, or other modifications |
|||
represent, as a whole, an original work of authorship. For the purposes |
|||
of this License, Derivative Works shall not include works that remain |
|||
separable from, or merely link (or bind by name) to the interfaces of, |
|||
the Work and Derivative Works thereof. |
|||
|
|||
"Contribution" shall mean any work of authorship, including |
|||
the original version of the Work and any modifications or additions |
|||
to that Work or Derivative Works thereof, that is intentionally |
|||
submitted to Licensor for inclusion in the Work by the copyright owner |
|||
or by an individual or Legal Entity authorized to submit on behalf of |
|||
the copyright owner. For the purposes of this definition, "submitted" |
|||
means any form of electronic, verbal, or written communication sent |
|||
to the Licensor or its representatives, including but not limited to |
|||
communication on electronic mailing lists, source code control systems, |
|||
and issue tracking systems that are managed by, or on behalf of, the |
|||
Licensor for the purpose of discussing and improving the Work, but |
|||
excluding communication that is conspicuously marked or otherwise |
|||
designated in writing by the copyright owner as "Not a Contribution." |
|||
|
|||
"Contributor" shall mean Licensor and any individual or Legal Entity |
|||
on behalf of whom a Contribution has been received by Licensor and |
|||
subsequently incorporated within the Work. |
|||
|
|||
2. Grant of Copyright License. Subject to the terms and conditions of |
|||
this License, each Contributor hereby grants to You a perpetual, |
|||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
|||
copyright license to reproduce, prepare Derivative Works of, |
|||
publicly display, publicly perform, sublicense, and distribute the |
|||
Work and such Derivative Works in Source or Object form. |
|||
|
|||
3. Grant of Patent License. Subject to the terms and conditions of |
|||
this License, each Contributor hereby grants to You a perpetual, |
|||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
|||
(except as stated in this section) patent license to make, have made, |
|||
use, offer to sell, sell, import, and otherwise transfer the Work, |
|||
where such license applies only to those patent claims licensable |
|||
by such Contributor that are necessarily infringed by their |
|||
Contribution(s) alone or by combination of their Contribution(s) |
|||
with the Work to which such Contribution(s) was submitted. If You |
|||
institute patent litigation against any entity (including a |
|||
cross-claim or counterclaim in a lawsuit) alleging that the Work |
|||
or a Contribution incorporated within the Work constitutes direct |
|||
or contributory patent infringement, then any patent licenses |
|||
granted to You under this License for that Work shall terminate |
|||
as of the date such litigation is filed. |
|||
|
|||
4. Redistribution. You may reproduce and distribute copies of the |
|||
Work or Derivative Works thereof in any medium, with or without |
|||
modifications, and in Source or Object form, provided that You |
|||
meet the following conditions: |
|||
|
|||
(a) You must give any other recipients of the Work or |
|||
Derivative Works a copy of this License; and |
|||
|
|||
(b) You must cause any modified files to carry prominent notices |
|||
stating that You changed the files; and |
|||
|
|||
(c) You must retain, in the Source form of any Derivative Works |
|||
that You distribute, all copyright, patent, trademark, and |
|||
attribution notices from the Source form of the Work, |
|||
excluding those notices that do not pertain to any part of |
|||
the Derivative Works; and |
|||
|
|||
(d) If the Work includes a "NOTICE" text file as part of its |
|||
distribution, then any Derivative Works that You distribute must |
|||
include a readable copy of the attribution notices contained |
|||
within such NOTICE file, excluding those notices that do not |
|||
pertain to any part of the Derivative Works, in at least one |
|||
of the following places: within a NOTICE text file distributed |
|||
as part of the Derivative Works; within the Source form or |
|||
documentation, if provided along with the Derivative Works; or, |
|||
within a display generated by the Derivative Works, if and |
|||
wherever such third-party notices normally appear. The contents |
|||
of the NOTICE file are for informational purposes only and |
|||
do not modify the License. You may add Your own attribution |
|||
notices within Derivative Works that You distribute, alongside |
|||
or as an addendum to the NOTICE text from the Work, provided |
|||
that such additional attribution notices cannot be construed |
|||
as modifying the License. |
|||
|
|||
You may add Your own copyright statement to Your modifications and |
|||
may provide additional or different license terms and conditions |
|||
for use, reproduction, or distribution of Your modifications, or |
|||
for any such Derivative Works as a whole, provided Your use, |
|||
reproduction, and distribution of the Work otherwise complies with |
|||
the conditions stated in this License. |
|||
|
|||
5. Submission of Contributions. Unless You explicitly state otherwise, |
|||
any Contribution intentionally submitted for inclusion in the Work |
|||
by You to the Licensor shall be under the terms and conditions of |
|||
this License, without any additional terms or conditions. |
|||
Notwithstanding the above, nothing herein shall supersede or modify |
|||
the terms of any separate license agreement you may have executed |
|||
with Licensor regarding such Contributions. |
|||
|
|||
6. Trademarks. This License does not grant permission to use the trade |
|||
names, trademarks, service marks, or product names of the Licensor, |
|||
except as required for reasonable and customary use in describing the |
|||
origin of the Work and reproducing the content of the NOTICE file. |
|||
|
|||
7. Disclaimer of Warranty. Unless required by applicable law or |
|||
agreed to in writing, Licensor provides the Work (and each |
|||
Contributor provides its Contributions) on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
|||
implied, including, without limitation, any warranties or conditions |
|||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
|||
PARTICULAR PURPOSE. You are solely responsible for determining the |
|||
appropriateness of using or redistributing the Work and assume any |
|||
risks associated with Your exercise of permissions under this License. |
|||
|
|||
8. Limitation of Liability. In no event and under no legal theory, |
|||
whether in tort (including negligence), contract, or otherwise, |
|||
unless required by applicable law (such as deliberate and grossly |
|||
negligent acts) or agreed to in writing, shall any Contributor be |
|||
liable to You for damages, including any direct, indirect, special, |
|||
incidental, or consequential damages of any character arising as a |
|||
result of this License or out of the use or inability to use the |
|||
Work (including but not limited to damages for loss of goodwill, |
|||
work stoppage, computer failure or malfunction, or any and all |
|||
other commercial damages or losses), even if such Contributor |
|||
has been advised of the possibility of such damages. |
|||
|
|||
9. Accepting Warranty or Additional Liability. While redistributing |
|||
the Work or Derivative Works thereof, You may choose to offer, |
|||
and charge a fee for, acceptance of support, warranty, indemnity, |
|||
or other liability obligations and/or rights consistent with this |
|||
License. However, in accepting such obligations, You may act only |
|||
on Your own behalf and on Your sole responsibility, not on behalf |
|||
of any other Contributor, and only if You agree to indemnify, |
|||
defend, and hold each Contributor harmless for any liability |
|||
incurred by, or claims asserted against, such Contributor by reason |
|||
of your accepting any such warranty or additional liability. |
|||
|
|||
END OF TERMS AND CONDITIONS |
|||
|
|||
APPENDIX: How to apply the Apache License to your work. |
|||
|
|||
To apply the Apache License to your work, attach the following |
|||
boilerplate notice, with the fields enclosed by brackets "[]" |
|||
replaced with your own identifying information. (Don't include |
|||
the brackets!) The text should be enclosed in the appropriate |
|||
comment syntax for the file format. We also recommend that a |
|||
file or class name and description of purpose be included on the |
|||
same "printed page" as the copyright notice for easier |
|||
identification within third-party archives. |
|||
|
|||
Copyright 2018 Six Labors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
@ -1,2 +1,17 @@ |
|||
@echo Off |
|||
call build\build.cmd |
|||
|
|||
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 |
|||
@ -0,0 +1,113 @@ |
|||
|
|||
# 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 |
|||
|
|||
Write-Host "Building projects" |
|||
dotnet build -c Release /p:packageversion=$version |
|||
|
|||
if ($LASTEXITCODE ){ Exit $LASTEXITCODE } |
|||
|
|||
if ( $env:CI -ne "True") { |
|||
dotnet test ./tests/ImageSharp.Tests/ImageSharp.Tests.csproj --no-build -c Release |
|||
} |
|||
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 } |
|||
@ -1,463 +0,0 @@ |
|||
// <copyright file="Program.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ConsoleApplication |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Xml; |
|||
using LibGit2Sharp; |
|||
using Microsoft.Build.Construction; |
|||
using Microsoft.Build.Evaluation; |
|||
using NuGet.Versioning; |
|||
|
|||
/// <summary>
|
|||
/// This updates the version numbers for all the projects in the src folder.
|
|||
/// The version number it will geneate is dependent on if this is a build from master or a branch/PR
|
|||
///
|
|||
/// If its a build on master
|
|||
/// We take the version number specified in project.json,
|
|||
/// count how meny commits the repo has had that will affect this project or its dependencies since the version number of manually changed
|
|||
/// If this is the first commit that effected this project since number change then leave the version number as defined i.e. will build 1.0.0 if thats in project.json
|
|||
/// unless it is a preview build number in which case we always add the counter
|
|||
///
|
|||
/// If the build is from a PR/branch
|
|||
/// We take the version number specified in project.json, append a tag for the branch/PR (so we can determin how each package was built)
|
|||
/// append number of commits effecting the project.
|
|||
///
|
|||
/// </summary>
|
|||
/// <example>
|
|||
/// for PR#123 and project.json version 2.0.1 and we have had 30 commits affecting the project
|
|||
/// we would end up with version number 2.0.1-PR124-00030
|
|||
///
|
|||
/// for branch `fix-stuff` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project
|
|||
/// we would end up with version number 2.0.1-alpha1-fix-stuff-00832
|
|||
///
|
|||
/// for `master` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project
|
|||
/// we would end up with version number 2.0.1-alpha1-00832
|
|||
///
|
|||
/// for `master` project.json version 2.0.1 and we have had 132 commits affecting the project
|
|||
/// we would end up with version number 2.0.1-CI-00132
|
|||
///
|
|||
/// for `master` project.json version 2.0.1 and we have had 1 commits affecting the project
|
|||
/// we would end up with version number 2.0.1
|
|||
///
|
|||
/// for `master` project.json version 2.0.1-alpha1 and we have had 1 commits affecting the project
|
|||
/// we would end up with version number 2.0.1-alpha1
|
|||
/// </example>
|
|||
/// <remarks>
|
|||
/// TODO Add the option for using this to update the version numbers in a project and its dependent references.
|
|||
/// </remarks>
|
|||
public class Program |
|||
{ |
|||
private const string FallbackTag = "CI"; |
|||
|
|||
/// <summary>
|
|||
/// Main entry point.
|
|||
/// </summary>
|
|||
/// <param name="args">The arguments.</param>
|
|||
public static void Main(string[] args) |
|||
{ |
|||
bool resetmode = args.Contains("reset"); |
|||
|
|||
// Find the project root
|
|||
string root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), "..")); |
|||
|
|||
// Lets find the repo
|
|||
Repository repo = new LibGit2Sharp.Repository(root); |
|||
|
|||
// Lets find all the project.json files in the src folder (don't care about versioning `tests`)
|
|||
IEnumerable<string> projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), "*.csproj", SearchOption.AllDirectories); |
|||
|
|||
ResetProject(projectFiles); |
|||
|
|||
// Open them and convert them to source projects
|
|||
List<SourceProject> projects = projectFiles.Select(x => ProjectRootElement.Open(x, ProjectCollection.GlobalProjectCollection, true)) |
|||
.Select(x => new SourceProject(x, repo.Info.WorkingDirectory)) |
|||
.ToList(); |
|||
|
|||
if (!resetmode) |
|||
{ |
|||
CaclulateProjectVersionNumber(projects, repo); |
|||
|
|||
UpdateVersionNumbers(projects); |
|||
|
|||
CreateBuildScript(projects, root); |
|||
|
|||
foreach (SourceProject p in projects) |
|||
{ |
|||
Console.WriteLine($"{p.Name} {p.FinalVersionNumber}"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static void CreateBuildScript(IEnumerable<SourceProject> projects, string root) |
|||
{ |
|||
string outputDir = Path.GetFullPath(Path.Combine(root, @"artifacts\bin\ImageSharp")); |
|||
|
|||
StringBuilder sb = new StringBuilder(); |
|||
foreach (SourceProject p in projects) |
|||
{ |
|||
sb.AppendLine($@"dotnet pack --configuration Release --output ""{outputDir}"" ""{p.ProjectFilePath}"""); |
|||
} |
|||
|
|||
File.WriteAllText("build-inner.cmd", sb.ToString()); |
|||
} |
|||
|
|||
private static void UpdateVersionNumbers(IEnumerable<SourceProject> projects) |
|||
{ |
|||
foreach (SourceProject p in projects) |
|||
{ |
|||
// create a backup file so we can rollback later without breaking formatting
|
|||
File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); |
|||
} |
|||
|
|||
foreach (SourceProject p in projects) |
|||
{ |
|||
// TODO force update of all dependent projects to point to the newest build.
|
|||
// we skip the build number and standard CI prefix on first commits
|
|||
string newVersion = p.FinalVersionNumber; |
|||
|
|||
p.UpdateVersion(newVersion); |
|||
} |
|||
} |
|||
|
|||
private static string CurrentBranch(Repository repo) |
|||
{ |
|||
// lets build version friendly commit
|
|||
string branch = repo.Head.FriendlyName; |
|||
|
|||
// lets see if we are running in appveyor and if we are use the environment variables instead of the head
|
|||
string appveryorBranch = Environment.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH"); |
|||
if (!string.IsNullOrWhiteSpace(appveryorBranch)) |
|||
{ |
|||
branch = appveryorBranch; |
|||
} |
|||
|
|||
string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); |
|||
if (!string.IsNullOrWhiteSpace(prNumber)) |
|||
{ |
|||
branch = $"PR{int.Parse(prNumber):000}"; |
|||
} |
|||
|
|||
// this will happen when checking out a comit directly and not a branch (like appveryor does when it builds)
|
|||
if (branch == "(no branch)") |
|||
{ |
|||
throw new Exception("unable to find branch"); |
|||
} |
|||
|
|||
// clean branch names (might need to be improved)
|
|||
branch = branch.Replace("/", "-").Replace("--", "-"); |
|||
|
|||
return branch; |
|||
} |
|||
|
|||
private static void CaclulateProjectVersionNumber(List<SourceProject> projects, Repository repo) |
|||
{ |
|||
string branch = CurrentBranch(repo); |
|||
|
|||
// populate the dependency chains
|
|||
projects.ForEach(x => x.PopulateDependencies(projects)); |
|||
|
|||
// update the final version based on the repo history and the currentr branch name
|
|||
projects.ForEach(x => x.CalculateVersion(repo, branch)); |
|||
} |
|||
|
|||
private static void ResetProject(IEnumerable<string> projectPaths) |
|||
{ |
|||
if (File.Exists("build-inner.cmd")) |
|||
{ |
|||
File.Delete("build-inner.cmd"); |
|||
} |
|||
|
|||
// revert the project.json change be reverting it but skipp all the git stuff as its not needed
|
|||
foreach (string p in projectPaths) |
|||
{ |
|||
if (File.Exists($"{p}.bak")) |
|||
{ |
|||
File.Copy($"{p}.bak", p, true); |
|||
File.Delete($"{p}.bak"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Project level logic
|
|||
/// </summary>
|
|||
public class SourceProject |
|||
{ |
|||
private readonly IEnumerable<string> dependencies; |
|||
private readonly ProjectRootElement project; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="SourceProject"/> class.
|
|||
/// </summary>
|
|||
/// <param name="project">The project.</param>
|
|||
/// <param name="root">The root.</param>
|
|||
public SourceProject(ProjectRootElement project, string root) |
|||
{ |
|||
this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value; |
|||
|
|||
this.ProjectDirectory = project.DirectoryPath.Substring(root.Length); |
|||
this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length); |
|||
this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File); |
|||
this.Version = new NuGetVersion(project.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); |
|||
this.dependencies = project.Items.Where(x => x.ItemType == "ProjectReference").Select(x => Path.GetFullPath(Path.Combine(project.DirectoryPath, x.Include))); |
|||
this.FinalVersionNumber = this.Version.ToFullString(); |
|||
this.project = project; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the project directory.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The project directory.
|
|||
/// </value>
|
|||
public string ProjectDirectory { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the version.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The version.
|
|||
/// </value>
|
|||
public NuGetVersion Version { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the dependent projects.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The dependent projects.
|
|||
/// </value>
|
|||
public List<SourceProject> DependentProjects { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the name.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The name.
|
|||
/// </value>
|
|||
public string Name { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the project file path.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The project file path.
|
|||
/// </value>
|
|||
public string ProjectFilePath { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the commit count since version change.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The commit count since version change.
|
|||
/// </value>
|
|||
public int CommitCountSinceVersionChange { get; private set; } = 0; |
|||
|
|||
/// <summary>
|
|||
/// Gets the full project file path.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The full project file path.
|
|||
/// </value>
|
|||
public string FullProjectFilePath { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the final version number.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The final version number.
|
|||
/// </value>
|
|||
public string FinalVersionNumber { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// Populates the dependencies.
|
|||
/// </summary>
|
|||
/// <param name="projects">The projects.</param>
|
|||
public void PopulateDependencies(IEnumerable<SourceProject> projects) |
|||
{ |
|||
this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.FullProjectFilePath)).ToList(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Update the version number in the project file
|
|||
/// </summary>
|
|||
/// <param name="versionnumber">the new version number to save.</param>
|
|||
internal void UpdateVersion(string versionnumber) |
|||
{ |
|||
this.project.AddProperty("VersionPrefix", versionnumber); |
|||
this.Version = new NuGetVersion(versionnumber); |
|||
this.project.Save(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Calculates the version.
|
|||
/// </summary>
|
|||
/// <param name="repo">The repo.</param>
|
|||
/// <param name="branch">The branch.</param>
|
|||
internal void CalculateVersion(Repository repo, string branch) |
|||
{ |
|||
foreach (Commit c in repo.Commits) |
|||
{ |
|||
if (!this.ApplyCommit(c, repo)) |
|||
{ |
|||
// we have finished lets populate the final version number
|
|||
this.FinalVersionNumber = this.CalculateVersionNumber(branch); |
|||
|
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private bool MatchPath(string path) |
|||
{ |
|||
if (path.StartsWith(this.ProjectDirectory, StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
if (this.DependentProjects.Any()) |
|||
{ |
|||
return this.DependentProjects.Any(x => x.MatchPath(path)); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private bool ApplyCommitInternal(Commit commit, TreeChanges changes, Repository repo) |
|||
{ |
|||
this.CommitCountSinceVersionChange++; |
|||
|
|||
// return false if this is a version number root
|
|||
TreeEntryChanges projectFileChange = changes.Where(x => x.Path?.Equals(this.ProjectFilePath, StringComparison.OrdinalIgnoreCase) == true).FirstOrDefault(); |
|||
if (projectFileChange != null) |
|||
{ |
|||
if (projectFileChange.Status == ChangeKind.Added) |
|||
{ |
|||
// the version must have been set here
|
|||
return false; |
|||
} |
|||
else |
|||
{ |
|||
Blob blob = repo.Lookup<Blob>(projectFileChange.Oid); |
|||
using (Stream s = blob.GetContentStream()) |
|||
{ |
|||
using (XmlReader reader = XmlReader.Create(s)) |
|||
{ |
|||
ProjectRootElement proj = ProjectRootElement.Create(reader); |
|||
NuGetVersion version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); |
|||
if (version != this.Version) |
|||
{ |
|||
// version changed
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// version must have been the same lets carry on
|
|||
return true; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
private bool ApplyCommit(Commit commit, Repository repo) |
|||
{ |
|||
foreach (Commit parent in commit.Parents) |
|||
{ |
|||
TreeChanges changes = repo.Diff.Compare<TreeChanges>(parent.Tree, commit.Tree); |
|||
|
|||
foreach (TreeEntryChanges change in changes) |
|||
{ |
|||
if (!string.IsNullOrWhiteSpace(change.OldPath)) |
|||
{ |
|||
if (this.MatchPath(change.OldPath)) |
|||
{ |
|||
return this.ApplyCommitInternal(commit, changes, repo); |
|||
} |
|||
} |
|||
|
|||
if (!string.IsNullOrWhiteSpace(change.Path)) |
|||
{ |
|||
if (this.MatchPath(change.Path)) |
|||
{ |
|||
return this.ApplyCommitInternal(commit, changes, repo); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
private string CalculateVersionNumber(string branch) |
|||
{ |
|||
string version = this.Version.ToFullString(); |
|||
|
|||
// master only
|
|||
if (this.CommitCountSinceVersionChange == 1 && branch == "master") |
|||
{ |
|||
if (this.Version.IsPrerelease) |
|||
{ |
|||
// prerelease always needs the build counter just not on a branch name
|
|||
return $"{version}-{this.CommitCountSinceVersionChange:00000}"; |
|||
} |
|||
|
|||
// this is the full release happy path, first commit after changing the version number
|
|||
return version; |
|||
} |
|||
|
|||
string rootSpecialVersion = string.Empty; |
|||
|
|||
if (this.Version.IsPrerelease) |
|||
{ |
|||
// probably a much easy way for doing this but it work sell enough for a build script
|
|||
string[] parts = version.Split(new[] { '-' }, 2); |
|||
version = parts[0]; |
|||
rootSpecialVersion = parts[1]; |
|||
} |
|||
|
|||
// if master and the version doesn't manually specify a prerelease tag force one on for CI builds
|
|||
if (branch == "master") |
|||
{ |
|||
if (!this.Version.IsPrerelease) |
|||
{ |
|||
branch = FallbackTag; |
|||
} |
|||
else |
|||
{ |
|||
branch = string.Empty; |
|||
} |
|||
} |
|||
|
|||
if (rootSpecialVersion.Length > 0) |
|||
{ |
|||
rootSpecialVersion = "-" + rootSpecialVersion; |
|||
} |
|||
|
|||
if (branch.Length > 0) |
|||
{ |
|||
branch = "-" + branch; |
|||
} |
|||
|
|||
int maxLength = 20; // dotnet will fail to populate the package if the tag is > 20
|
|||
maxLength -= rootSpecialVersion.Length; // this is a required tag
|
|||
maxLength -= 7; // for the counter and dashes
|
|||
|
|||
if (branch.Length > maxLength) |
|||
{ |
|||
branch = branch.Substring(0, maxLength); |
|||
} |
|||
|
|||
return $"{version}{rootSpecialVersion}{branch}-{this.CommitCountSinceVersionChange:00000}"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
{ |
|||
"profiles": { |
|||
"build": { |
|||
"commandName": "Project", |
|||
"commandLineArgs": "reset" |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
@echo Off |
|||
set buildRoot="%cd%" |
|||
|
|||
ECHO Restoring packages |
|||
dotnet restore |
|||
|
|||
ECHO Updating version numbers and generating build script |
|||
cd %~dp0 |
|||
dotnet run -- update |
|||
cd %buildRoot% |
|||
|
|||
ECHO Building package |
|||
call %~dp0build-inner.cmd |
|||
|
|||
ECHO Reset version numbers |
|||
cd %~dp0 |
|||
dotnet run -- reset |
|||
cd %buildRoot% |
|||
@ -1,16 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp1.1</TargetFramework> |
|||
<DebugType>portable</DebugType> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<AssemblyName>build</AssemblyName> |
|||
<OutputType>Exe</OutputType> |
|||
<PackageId>build</PackageId> |
|||
<CodeAnalysisRuleSet>..\ImageSharp.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-1-003177" /> |
|||
<PackageReference Include="Microsoft.Build" Version="15.1.548" /> |
|||
<PackageReference Include="LibGit2Sharp.Portable" Version="0.24.10" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,8 +0,0 @@ |
|||
@echo Off |
|||
|
|||
set buildRoot="%cd%" |
|||
cd %~dp0 |
|||
|
|||
dotnet run -- reset |
|||
|
|||
cd %buildRoot% |
|||
@ -1,4 +0,0 @@ |
|||
#recipe Docs |
|||
Settings[Keys.Host] = "imagesharp.org"; |
|||
Settings[Keys.Title] = "Image Sharp"; |
|||
FileSystem.OutputPath = "./docs"; |
|||
@ -1,50 +1,54 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<Description>An extension to ImageSharp that allows the drawing of images, paths, and text.</Description> |
|||
<AssemblyTitle>ImageSharp.Drawing</AssemblyTitle> |
|||
<VersionPrefix>1.0.0-alpha9</VersionPrefix> |
|||
<Authors>James Jackson-South and contributors</Authors> |
|||
<TargetFramework>netstandard1.1</TargetFramework> |
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<AssemblyName>ImageSharp.Drawing</AssemblyName> |
|||
<PackageId>ImageSharp.Drawing</PackageId> |
|||
<PackageTags>Image Draw Shape Path Font</PackageTags> |
|||
<PackageIconUrl>https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png</PackageIconUrl> |
|||
<PackageProjectUrl>https://github.com/JimBobSquarePants/ImageSharp</PackageProjectUrl> |
|||
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl> |
|||
<RepositoryType>git</RepositoryType> |
|||
<RepositoryUrl>https://github.com/JimBobSquarePants/ImageSharp</RepositoryUrl> |
|||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> |
|||
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute> |
|||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> |
|||
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> |
|||
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> |
|||
<DebugType Condition="$(codecov) != ''">full</DebugType> |
|||
<DebugType Condition="$(codecov) == ''">portable</DebugType> |
|||
<DebugSymbols>True</DebugSymbols> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" /> |
|||
<AdditionalFiles Include="..\Shared\stylecop.json" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\ImageSharp\ImageSharp.csproj" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="SixLabors.Shapes.Text" Version="0.1.0-alpha0018" /> |
|||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta001"> |
|||
<PrivateAssets>All</PrivateAssets> |
|||
</PackageReference> |
|||
</ItemGroup> |
|||
<PropertyGroup> |
|||
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
|||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<Description>An extension to ImageSharp that allows the drawing of images, paths, and text.</Description> |
|||
<AssemblyTitle>SixLabors.ImageSharp.Drawing</AssemblyTitle> |
|||
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix> |
|||
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix> |
|||
<Authors>SixLabors and contributors</Authors> |
|||
<TargetFrameworks>netstandard1.1;netstandard2.0</TargetFrameworks> |
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<AssemblyName>SixLabors.ImageSharp.Drawing</AssemblyName> |
|||
<PackageId>SixLabors.ImageSharp.Drawing</PackageId> |
|||
<PackageTags>Image Draw Shape Path Font</PackageTags> |
|||
<PackageIconUrl>https://raw.githubusercontent.com/SixLabors/ImageSharp/master/build/icons/imagesharp-logo-128.png</PackageIconUrl> |
|||
<PackageProjectUrl>https://github.com/SixLabors/ImageSharp</PackageProjectUrl> |
|||
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl> |
|||
<RepositoryType>git</RepositoryType> |
|||
<RepositoryUrl>https://github.com/SixLabors/ImageSharp</RepositoryUrl> |
|||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> |
|||
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute> |
|||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> |
|||
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> |
|||
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> |
|||
<DebugType Condition="$(codecov) != ''">full</DebugType> |
|||
<DebugType Condition="$(codecov) == ''">portable</DebugType> |
|||
<DebugSymbols>True</DebugSymbols> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\ImageSharp\ImageSharp.csproj" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="SixLabors.Core" Version="1.0.0-ci0005" /> |
|||
<PackageReference Include="SixLabors.Shapes.Text" Version="1.0.0-ci0005" /> |
|||
<PackageReference Include="SixLabors.Shapes" Version="1.0.0-ci0005" /> |
|||
<AdditionalFiles Include="..\..\stylecop.json" /> |
|||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004"> |
|||
<PrivateAssets>All</PrivateAssets> |
|||
</PackageReference> |
|||
</ItemGroup> |
|||
<PropertyGroup> |
|||
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet> |
|||
<RootNamespace>SixLabors.ImageSharp.Drawing</RootNamespace> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
|||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -1,23 +0,0 @@ |
|||
// <copyright file="PointInfo.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Drawing |
|||
{ |
|||
/// <summary>
|
|||
/// Returns details about how far away from the inside of a shape and the color the pixel could be.
|
|||
/// </summary>
|
|||
public struct PointInfo |
|||
{ |
|||
/// <summary>
|
|||
/// The distance along path
|
|||
/// </summary>
|
|||
public float DistanceAlongPath; |
|||
|
|||
/// <summary>
|
|||
/// The distance from path
|
|||
/// </summary>
|
|||
public float DistanceFromPath; |
|||
} |
|||
} |
|||
@ -1,6 +1,4 @@ |
|||
// <copyright file="AssemblyInfo.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
// Common values read from `AssemblyInfo.Common.cs`
|
|||
|
|||
@ -0,0 +1,145 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Advanced |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods over Image{TPixel}
|
|||
/// </summary>
|
|||
public static class AdvancedImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the configuration for the image.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The Pixel format.</typeparam>
|
|||
/// <param name="source">The source image</param>
|
|||
/// <returns>Returns the configuration.</returns>
|
|||
public static Configuration GetConfiguration<TPixel>(this Image<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> GetConfiguration((IConfigurable)source); |
|||
|
|||
/// <summary>
|
|||
/// Returns a reference to the 0th element of the Pixel buffer,
|
|||
/// allowing direct manipulation of pixel data through unsafe operations.
|
|||
/// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The Pixel format.</typeparam>
|
|||
/// <param name="source">The source image frame</param>
|
|||
/// <returns>A pinnable reference the first root of the pixel buffer.</returns>
|
|||
public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer<TPixel>(this ImageFrame<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> ref DangerousGetPinnableReferenceToPixelBuffer((IPixelSource<TPixel>)source); |
|||
|
|||
/// <summary>
|
|||
/// Returns a reference to the 0th element of the Pixel buffer,
|
|||
/// allowing direct manipulation of pixel data through unsafe operations.
|
|||
/// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The Pixel format.</typeparam>
|
|||
/// <param name="source">The source image</param>
|
|||
/// <returns>A pinnable reference the first root of the pixel buffer.</returns>
|
|||
public static ref TPixel DangerousGetPinnableReferenceToPixelBuffer<TPixel>(this Image<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> ref source.Frames.RootFrame.DangerousGetPinnableReferenceToPixelBuffer(); |
|||
|
|||
/// <summary>
|
|||
/// Gets the representation of the pixels as an area of contiguous memory in the given pixel format.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <returns>The <see cref="Span{TPixel}"/></returns>
|
|||
internal static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> GetSpan(source); |
|||
|
|||
/// <summary>
|
|||
/// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <param name="row">The row.</param>
|
|||
/// <returns>The <see cref="Span{TPixel}"/></returns>
|
|||
internal static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> source, int row) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> GetSpan(source, row); |
|||
|
|||
/// <summary>
|
|||
/// Gets the representation of the pixels as an area of contiguous memory in the given pixel format.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <returns>The <see cref="Span{TPixel}"/></returns>
|
|||
internal static Span<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.Frames.RootFrame.GetPixelSpan(); |
|||
|
|||
/// <summary>
|
|||
/// Gets the representation of the pixels as an area of contiguous memory at row 'y' beginning from the the first pixel on that row.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <param name="row">The row.</param>
|
|||
/// <returns>The <see cref="Span{TPixel}"/></returns>
|
|||
internal static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, int row) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.Frames.RootFrame.GetPixelRowSpan(row); |
|||
|
|||
/// <summary>
|
|||
/// Gets the span to the backing buffer.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <returns>The span retuned from Pixel source</returns>
|
|||
private static Span<TPixel> GetSpan<TPixel>(IPixelSource<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.PixelBuffer.Span; |
|||
|
|||
/// <summary>
|
|||
/// Gets the span to the backing buffer at the given row.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <param name="row">The row.</param>
|
|||
/// <returns>
|
|||
/// The span retuned from Pixel source
|
|||
/// </returns>
|
|||
private static Span<TPixel> GetSpan<TPixel>(IPixelSource<TPixel> source, int row) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> GetSpan(source.PixelBuffer, row); |
|||
|
|||
/// <summary>
|
|||
/// Gets the span to the backing buffer at the given row.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
/// <param name="source">The source.</param>
|
|||
/// <param name="row">The row.</param>
|
|||
/// <returns>
|
|||
/// The span retuned from Pixel source
|
|||
/// </returns>
|
|||
private static Span<TPixel> GetSpan<TPixel>(Buffer2D<TPixel> source, int row) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.Span.Slice(row * source.Width, source.Width); |
|||
|
|||
/// <summary>
|
|||
/// Gets the configuration.
|
|||
/// </summary>
|
|||
/// <param name="source">The source image</param>
|
|||
/// <returns>Returns the bounds of the image</returns>
|
|||
private static Configuration GetConfiguration(IConfigurable source) |
|||
=> source?.Configuration ?? Configuration.Default; |
|||
|
|||
/// <summary>
|
|||
/// Returns a reference to the 0th element of the Pixel buffer.
|
|||
/// Such a reference can be used for pinning but must never be dereferenced.
|
|||
/// </summary>
|
|||
/// <param name="source">The source image frame</param>
|
|||
/// <returns>A reference to the element.</returns>
|
|||
private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer<TPixel>(IPixelSource<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> ref source.PixelBuffer.Span.DangerousGetPinnableReference(); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Advanced |
|||
{ |
|||
/// <summary>
|
|||
/// Encapsulates the properties for configuration
|
|||
/// </summary>
|
|||
internal interface IConfigurable |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the configuration.
|
|||
/// </summary>
|
|||
Configuration Configuration { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.MetaData; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Advanced |
|||
{ |
|||
/// <summary>
|
|||
/// Encapsulates the basic properties and methods required to manipulate images.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|||
internal interface IPixelSource<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the pixel buffer.
|
|||
/// </summary>
|
|||
Buffer2D<TPixel> PixelBuffer { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Advanced; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Mutates the source image by applying the image operation to it.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image to mutate.</param>
|
|||
/// <param name="operation">The operation to perform on the source.</param>
|
|||
public static void Mutate<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext<TPixel>> operation) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Guard.NotNull(operation, nameof(operation)); |
|||
Guard.NotNull(source, nameof(source)); |
|||
|
|||
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, true); |
|||
operation(operationsRunner); |
|||
operationsRunner.Apply(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mutates the source image by applying the operations to it.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image to mutate.</param>
|
|||
/// <param name="operations">The operations to perform on the source.</param>
|
|||
public static void Mutate<TPixel>(this Image<TPixel> source, params IImageProcessor<TPixel>[] operations) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Guard.NotNull(operations, nameof(operations)); |
|||
Guard.NotNull(source, nameof(source)); |
|||
|
|||
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, true); |
|||
operationsRunner.ApplyProcessors(operations); |
|||
operationsRunner.Apply(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a deep clone of the current image. The clone is then mutated by the given operation.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image to clone.</param>
|
|||
/// <param name="operation">The operation to perform on the clone.</param>
|
|||
/// <returns>The new <see cref="Image{TPixel}"/></returns>
|
|||
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, Action<IImageProcessingContext<TPixel>> operation) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Guard.NotNull(operation, nameof(operation)); |
|||
Guard.NotNull(source, nameof(source)); |
|||
|
|||
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false); |
|||
operation(operationsRunner); |
|||
return operationsRunner.Apply(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a deep clone of the current image. The clone is then mutated by the given operations.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image to clone.</param>
|
|||
/// <param name="operations">The operations to perform on the clone.</param>
|
|||
/// <returns>The new <see cref="Image{TPixel}"/></returns>
|
|||
public static Image<TPixel> Clone<TPixel>(this Image<TPixel> source, params IImageProcessor<TPixel>[] operations) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
Guard.NotNull(operations, nameof(operations)); |
|||
Guard.NotNull(source, nameof(source)); |
|||
|
|||
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false); |
|||
operationsRunner.ApplyProcessors(operations); |
|||
return operationsRunner.Apply(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies the given <see cref="IImageProcessor{TPixel}"/> collection against the context
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image processing context.</param>
|
|||
/// <param name="operations">The operations to perform on the source.</param>
|
|||
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
|
|||
public static IImageProcessingContext<TPixel> ApplyProcessors<TPixel>(this IImageProcessingContext<TPixel> source, params IImageProcessor<TPixel>[] operations) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
foreach (IImageProcessor<TPixel> p in operations) |
|||
{ |
|||
source = source.ApplyProcessor(p); |
|||
} |
|||
|
|||
return source; |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue