Browse Source

Merge remote-tracking branch 'upstream/master' into feature/stylecopTests

# Conflicts:
#	tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
#	tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
#	tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs
#	tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
#	tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
pull/1090/head
Brian Popow 6 years ago
parent
commit
32bc4229f2
  1. 59
      .github/workflows/build-and-test.yml
  2. 2
      .gitignore
  3. 3
      Directory.Build.props
  4. 31
      ImageSharp.sln
  5. 8
      README.md
  6. 15
      ci-build.ps1
  7. 11
      ci-pack.ps1
  8. 4
      ci-test.ps1
  9. 7
      codecov.yml
  10. 28
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  11. 4
      src/ImageSharp/Advanced/AotCompilerTools.cs
  12. 16
      src/ImageSharp/Advanced/IConfigurable.cs
  13. 16
      src/ImageSharp/Advanced/IConfigurationProvider.cs
  14. 2
      src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs
  15. 2
      src/ImageSharp/Configuration.cs
  16. 2
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  17. 23
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  18. 8
      src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs
  19. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  20. 89
      src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
  21. 4
      src/ImageSharp/Formats/Png/PngMetadata.cs
  22. 22
      src/ImageSharp/Image.cs
  23. 28
      src/ImageSharp/ImageFrame.cs
  24. 12
      src/ImageSharp/ImageFrame{TPixel}.cs
  25. 2
      src/ImageSharp/Image{TPixel}.cs
  26. 2
      src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs
  27. 5
      src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs
  28. 5
      src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs
  29. 4
      src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs
  30. 2
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs
  31. 3
      src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs
  32. 98
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs
  33. 86
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs
  34. 98
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs
  35. 80
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs
  36. 80
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs
  37. 80
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs
  38. 80
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs
  39. 80
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs
  40. 86
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs
  41. 82
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs
  42. 94
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs
  43. 82
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs
  44. 36
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude
  45. 18
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs
  46. 26
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs
  47. 288
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
  48. 24
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
  49. 43
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  50. 10
      src/ImageSharp/Primitives/ColorMatrix.cs
  51. 102
      src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs
  52. 102
      src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs
  53. 27
      src/ImageSharp/Processing/PixelRowOperation.cs
  54. 15
      src/ImageSharp/Processing/PixelShader.cs
  55. 16
      src/ImageSharp/Processing/PositionAwarePixelShader.cs
  56. 147
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
  57. 39
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs
  58. 21
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs
  59. 18
      src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel}.cs
  60. 58
      src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs
  61. 39
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs
  62. 19
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs
  63. 58
      src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs
  64. 10
      src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs
  65. 8
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs
  66. 8
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs
  67. 22
      src/ImageSharp/Processing/Processors/Quantization/FrameQuantizer{TPixel}.cs
  68. 10
      src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs
  69. 8
      src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs
  70. 5
      src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs
  71. 4
      src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs
  72. 42
      src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs
  73. 9
      src/ImageSharp/Processing/Processors/Quantization/WuQuantizer.cs
  74. 3
      tests/Directory.Build.props
  75. 26
      tests/Directory.Build.targets
  76. 3
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs
  77. 24
      tests/ImageSharp.Sandbox46/README.md
  78. 10
      tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj
  79. 10
      tests/ImageSharp.Tests.ProfilingSandbox/Program.cs
  80. 2
      tests/ImageSharp.Tests.ProfilingSandbox/README.md
  81. 0
      tests/ImageSharp.Tests.ProfilingSandbox/app.config
  82. 6
      tests/ImageSharp.Tests/AssemblyInfo.cs
  83. 27
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  84. 27
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  85. 27
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  86. 48
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  87. 1
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  88. 185
      tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs
  89. 4
      tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs
  90. 90
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs
  91. 20
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  92. 2
      tests/ImageSharp.Tests/Primitives/ColorMatrixTests.cs
  93. 61
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  94. 8
      tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs
  95. 28
      tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs
  96. 100
      tests/ImageSharp.Tests/TestUtilities/BasicSerializer.cs
  97. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs
  98. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  99. 3
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs
  100. 2
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs

59
.github/workflows/build-and-test.yml

@ -82,24 +82,67 @@ jobs:
shell: pwsh shell: pwsh
run: ./ci-test.ps1 "${{matrix.options.os}}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}" run: ./ci-test.ps1 "${{matrix.options.os}}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}"
env: env:
CI : True CI: True
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
# Avoid "Please provide the repository token to upload reports via `-t :repository-token`"
# https://community.codecov.io/t/whitelist-github-action-servers-to-upload-without-a-token/491/10
# https://github.community/t5/GitHub-Actions/Make-secrets-available-to-builds-of-forks/m-p/42814/highlight/true#M5129
- name: Update Codecov - name: Update Codecov
uses: iansu/codecov-action-node@v1.0.0 uses: iansu/codecov-action-node@v1.0.0
if: matrix.options.codecov == true if: matrix.options.codecov == true && startsWith(github.repository, 'SixLabors')
with: with:
token: ${{secrets.CODECOV_TOKEN}} token: 0ef021c7-2679-4012-b42f-4bed33d99450
file: "coverage.${{matrix.options.framework}}.xml"
flags: unittests flags: unittests
- name: Pack # We can use this filter as we know it happens only once and takes the most time to complete. Publish:
if: (github.event_name == 'push') && (matrix.options.codecov == true) needs: [Build]
runs-on: windows-latest
if: (github.event_name == 'push')
steps:
- uses: actions/checkout@v2
- name: Install NuGet
uses: NuGet/setup-nuget@v1
- name: Setup Git
shell: bash
run: |
git config --global core.autocrlf false
git config --global core.longpaths true
git fetch --prune --unshallow
git submodule -q update --init --recursive
- name: Fetch Tags for GitVersion
run: |
git fetch --tags
- name: Fetch master for GitVersion
if: github.ref != 'refs/heads/master'
run: git branch --create-reflog master origin/master
- name: Install GitVersion
uses: gittools/actions/setup-gitversion@v0.3
with:
versionSpec: "5.1.x"
- name: Use GitVersion
id: gitversion # step id used as reference for output values
uses: gittools/actions/execute-gitversion@v0.3
- name: Setup DotNet SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.101"
- name: Pack
shell: pwsh shell: pwsh
run: ./ci-build.ps1 "${{steps.gitversion.outputs.nuGetVersion}}" run: ./ci-pack.ps1 "${{steps.gitversion.outputs.nuGetVersion}}"
- name: Publish to MyGet - name: Publish to MyGet
if: (github.event_name == 'push') && (matrix.options.codecov == true)
shell: pwsh shell: pwsh
run: nuget.exe push .\artifacts\*.nupkg ${{secrets.MYGET_TOKEN}} -Source https://www.myget.org/F/sixlabors/api/v2/package run: nuget.exe push .\artifacts\*.nupkg ${{secrets.MYGET_TOKEN}} -Source https://www.myget.org/F/sixlabors/api/v2/package
# TODO: If github.ref starts with 'refs/tags' then it was tag push and we can optionally push out package to nuget.org # TODO: If github.ref starts with 'refs/tags' then it was tag push and we can optionally push out package to nuget.org

2
.gitignore

@ -216,7 +216,7 @@ artifacts/
*.csproj.bak *.csproj.bak
#CodeCoverage #CodeCoverage
/ImageSharp.Coverage.xml *.lcov
# Tests # Tests
**/Images/ActualOutput **/Images/ActualOutput

3
Directory.Build.props

@ -91,8 +91,9 @@
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<RestoreSources> <RestoreSources>
https://www.myget.org/F/sixlabors/api/v3/index.json; https://www.myget.org/F/sixlabors/api/v3/index.json;
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
https://api.nuget.org/v3/index.json; https://api.nuget.org/v3/index.json;
<!-- Contains RemoteExecutor. Taken from: https://github.com/dotnet/runtime/blob/master/NuGet.config -->
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;
</RestoreSources> </RestoreSources>
<SixLaborsPublicKey>002400000c8000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97</SixLaborsPublicKey> <SixLaborsPublicKey>002400000c8000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97</SixLaborsPublicKey>
<UseSharedCompilation>true</UseSharedCompilation> <UseSharedCompilation>true</UseSharedCompilation>

31
ImageSharp.sln

@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore .gitignore = .gitignore
.gitmodules = .gitmodules .gitmodules = .gitmodules
ci-build.ps1 = ci-build.ps1 ci-build.ps1 = ci-build.ps1
ci-pack.ps1 = ci-pack.ps1
ci-test.ps1 = ci-test.ps1 ci-test.ps1 = ci-test.ps1
Directory.Build.props = Directory.Build.props Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets Directory.Build.targets = Directory.Build.targets
@ -322,8 +323,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Tests", "tests\I
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Benchmarks", "tests\ImageSharp.Benchmarks\ImageSharp.Benchmarks.csproj", "{2BF743D8-2A06-412D-96D7-F448F00C5EA5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Benchmarks", "tests\ImageSharp.Benchmarks\ImageSharp.Benchmarks.csproj", "{2BF743D8-2A06-412D-96D7-F448F00C5EA5}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Sandbox46", "tests\ImageSharp.Sandbox46\ImageSharp.Sandbox46.csproj", "{561B880A-D9EE-44EF-90F5-817C54A9D9AB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{C0D7754B-5277-438E-ABEB-2BA34401B5A7}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{C0D7754B-5277-438E-ABEB-2BA34401B5A7}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml .github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
@ -331,6 +330,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
EndProject EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedInfrastructure", "shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.shproj", "{68A8CC40-6AED-4E96-B524-31B1158FDEEA}" Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedInfrastructure", "shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.shproj", "{68A8CC40-6AED-4E96-B524-31B1158FDEEA}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Tests.ProfilingSandbox", "tests\ImageSharp.Tests.ProfilingSandbox\ImageSharp.Tests.ProfilingSandbox.csproj", "{FC527290-2F22-432C-B77B-6E815726B02C}"
EndProject
Global Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13 shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
@ -380,18 +381,18 @@ Global
{2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x64.Build.0 = Release|Any CPU {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x64.Build.0 = Release|Any CPU
{2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.ActiveCfg = Release|Any CPU {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.ActiveCfg = Release|Any CPU
{2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.Build.0 = Release|Any CPU {2BF743D8-2A06-412D-96D7-F448F00C5EA5}.Release|x86.Build.0 = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x64.ActiveCfg = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|x64.ActiveCfg = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x64.Build.0 = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|x64.Build.0 = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x86.ActiveCfg = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|x86.ActiveCfg = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Debug|x86.Build.0 = Debug|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Debug|x86.Build.0 = Debug|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|Any CPU.Build.0 = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|Any CPU.Build.0 = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x64.ActiveCfg = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|x64.ActiveCfg = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x64.Build.0 = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|x64.Build.0 = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x86.ActiveCfg = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|x86.ActiveCfg = Release|Any CPU
{561B880A-D9EE-44EF-90F5-817C54A9D9AB}.Release|x86.Build.0 = Release|Any CPU {FC527290-2F22-432C-B77B-6E815726B02C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -415,9 +416,9 @@ Global
{E1C42A6F-913B-4A7B-B1A8-2BB62843B254} = {9DA226A1-8656-49A8-A58A-A8B5C081AD66} {E1C42A6F-913B-4A7B-B1A8-2BB62843B254} = {9DA226A1-8656-49A8-A58A-A8B5C081AD66}
{EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} {EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{2BF743D8-2A06-412D-96D7-F448F00C5EA5} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} {2BF743D8-2A06-412D-96D7-F448F00C5EA5} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{561B880A-D9EE-44EF-90F5-817C54A9D9AB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{C0D7754B-5277-438E-ABEB-2BA34401B5A7} = {1799C43E-5C54-4A8F-8D64-B1475241DB0D} {C0D7754B-5277-438E-ABEB-2BA34401B5A7} = {1799C43E-5C54-4A8F-8D64-B1475241DB0D}
{68A8CC40-6AED-4E96-B524-31B1158FDEEA} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {68A8CC40-6AED-4E96-B524-31B1158FDEEA} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{FC527290-2F22-432C-B77B-6E815726B02C} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795} SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}

8
README.md

@ -8,6 +8,8 @@ SixLabors.ImageSharp
<div align="center"> <div align="center">
[![Build Status](https://img.shields.io/github/workflow/status/SixLabors/ImageSharp/Build/master)](https://github.com/SixLabors/ImageSharp/actions)
[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/SixLabors/ImageSharp/master/LICENSE) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/SixLabors/ImageSharp/master/LICENSE)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ImageSharp/General?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ImageSharp/General?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=flat&logo=twitter)](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) [![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=flat&logo=twitter)](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)
@ -45,12 +47,6 @@ The **ImageSharp** library is made up of multiple packages:
- Transform methods like Resize, Crop, Skew, Rotate - anything that alters the dimensions of the image - 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 - Non-transform methods like Gaussian Blur, Pixelate, Edge Detection - anything that maintains the original image dimensions
### Build Status
|Build Status|Code Coverage|
|:----------:|:-----------:|
|[![Build Status](https://img.shields.io/github/workflow/status/SixLabors/ImageSharp/Build/master)](https://github.com/SixLabors/ImageSharp/actions)|[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)|
### Questions? ### Questions?
- Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. **Do not** open issues for questions! - Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. **Do not** open issues for questions!

15
ci-build.ps1

@ -1,20 +1,13 @@
param( param(
[Parameter(Mandatory, Position = 0)] [Parameter(Mandatory, Position = 0)]
[string]$version, [string]$version,
[Parameter(Mandatory = $false, Position = 1)] [Parameter(Mandatory = $true, Position = 1)]
[string]$targetFramework = 'ALL' [string]$targetFramework
) )
dotnet clean -c Release dotnet clean -c Release
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY" $repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
if ($targetFramework -ne 'ALL') {
# Building for a specific framework. # Building for a specific framework.
dotnet build -c Release -f $targetFramework /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl dotnet build -c Release -f $targetFramework /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl
}
else {
# Building for packing and publishing.
dotnet pack -c Release --output "$PSScriptRoot/artifacts" /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl
}

11
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

4
ci-test.ps1

@ -17,7 +17,7 @@ if ($codecov -eq 'true') {
# Allow toggling of profile to workaround any potential JIT errors caused by code injection. # Allow toggling of profile to workaround any potential JIT errors caused by code injection.
dotnet clean -c $codecovProfile dotnet clean -c $codecovProfile
dotnet test -c $codecovProfile -f $targetFramework /p:codecov=true 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) { elseif ($platform -eq '-x86' -and $targetFramework -match $netFxRegex) {
@ -34,4 +34,4 @@ elseif ($platform -eq '-x86' -and $targetFramework -match $netFxRegex) {
else { else {
dotnet test --no-build -c Release -f $targetFramework dotnet test --no-build -c Release -f $targetFramework
} }

7
codecov.yml

@ -0,0 +1,7 @@
# Documentation: https://docs.codecov.io/docs/codecov-yaml
codecov:
# Avoid "Missing base report"
# https://github.com/codecov/support/issues/363
# https://docs.codecov.io/docs/comparing-commits
allow_coverage_offsets: true

28
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -29,7 +29,23 @@ namespace SixLabors.ImageSharp.Advanced
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <returns>Returns the configuration.</returns> /// <returns>Returns the configuration.</returns>
public static Configuration GetConfiguration(this Image source) public static Configuration GetConfiguration(this Image source)
=> GetConfiguration((IConfigurable)source); => GetConfiguration((IConfigurationProvider)source);
/// <summary>
/// Gets the configuration for the image frame.
/// </summary>
/// <param name="source">The source image.</param>
/// <returns>Returns the configuration.</returns>
public static Configuration GetConfiguration(this ImageFrame source)
=> GetConfiguration((IConfigurationProvider)source);
/// <summary>
/// Gets the configuration .
/// </summary>
/// <param name="source">The source image</param>
/// <returns>Returns the bounds of the image</returns>
private static Configuration GetConfiguration(IConfigurationProvider source)
=> source?.Configuration ?? Configuration.Default;
/// <summary> /// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory in the source image's pixel format /// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory in the source image's pixel format
@ -158,17 +174,9 @@ namespace SixLabors.ImageSharp.Advanced
/// </summary> /// </summary>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <returns>Returns the configuration.</returns> /// <returns>Returns the configuration.</returns>
internal static MemoryAllocator GetMemoryAllocator(this IConfigurable source) internal static MemoryAllocator GetMemoryAllocator(this IConfigurationProvider source)
=> GetConfiguration(source).MemoryAllocator; => GetConfiguration(source).MemoryAllocator;
/// <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> /// <summary>
/// Returns a reference to the 0th element of the Pixel buffer. /// Returns a reference to the 0th element of the Pixel buffer.
/// Such a reference can be used for pinning but must never be dereferenced. /// Such a reference can be used for pinning but must never be dereferenced.

4
src/ImageSharp/Advanced/AotCompilerTools.cs

@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Advanced
private static void AotCompileOctreeQuantizer<TPixel>() private static void AotCompileOctreeQuantizer<TPixel>()
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (var test = new OctreeFrameQuantizer<TPixel>(new OctreeQuantizer(false))) using (var test = new OctreeFrameQuantizer<TPixel>(Configuration.Default, new OctreeQuantizer(false)))
{ {
test.AotGetPalette(); test.AotGetPalette();
} }
@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.Advanced
private static void AotCompileWuQuantizer<TPixel>() private static void AotCompileWuQuantizer<TPixel>()
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (var test = new WuFrameQuantizer<TPixel>(Configuration.Default.MemoryAllocator, new WuQuantizer(false))) using (var test = new WuFrameQuantizer<TPixel>(Configuration.Default, new WuQuantizer(false)))
{ {
test.QuantizeFrame(new ImageFrame<TPixel>(Configuration.Default, 1, 1)); test.QuantizeFrame(new ImageFrame<TPixel>(Configuration.Default, 1, 1));
test.AotGetPalette(); test.AotGetPalette();

16
src/ImageSharp/Advanced/IConfigurable.cs

@ -1,16 +0,0 @@
// 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; }
}
}

16
src/ImageSharp/Advanced/IConfigurationProvider.cs

@ -0,0 +1,16 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Advanced
{
/// <summary>
/// Defines the contract for objects that can provide access to configuration.
/// </summary>
internal interface IConfigurationProvider
{
/// <summary>
/// Gets the configuration which allows altering default behaviour or extending the library.
/// </summary>
Configuration Configuration { get; }
}
}

2
src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
/// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param> /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param>
public static void IterateRows(Rectangle rectangle, Configuration configuration, Action<RowInterval> body) public static void IterateRows(Rectangle rectangle, Configuration configuration, Action<RowInterval> body)
{ {
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration); var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows(rectangle, parallelSettings, body); IterateRows(rectangle, parallelSettings, body);
} }

2
src/ImageSharp/Configuration.cs

@ -16,7 +16,7 @@ using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
/// <summary> /// <summary>
/// Provides configuration code which allows altering default behaviour or extending the library. /// Provides configuration which allows altering default behaviour or extending the library.
/// </summary> /// </summary>
public sealed class Configuration public sealed class Configuration
{ {

2
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
public void Encode<TPixel>(Image<TPixel> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
var encoder = new GifEncoderCore(image.GetConfiguration().MemoryAllocator, this); var encoder = new GifEncoderCore(image.GetConfiguration(), this);
encoder.Encode(image, stream); encoder.Encode(image, stream);
} }
} }

23
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -53,11 +53,12 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GifEncoderCore"/> class. /// Initializes a new instance of the <see cref="GifEncoderCore"/> class.
/// </summary> /// </summary>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
public GifEncoderCore(MemoryAllocator memoryAllocator, IGifEncoderOptions options) public GifEncoderCore(Configuration configuration, IGifEncoderOptions options)
{ {
this.memoryAllocator = memoryAllocator; this.configuration = configuration;
this.memoryAllocator = configuration.MemoryAllocator;
this.quantizer = options.Quantizer; this.quantizer = options.Quantizer;
this.colorTableMode = options.ColorTableMode; this.colorTableMode = options.ColorTableMode;
} }
@ -74,16 +75,14 @@ namespace SixLabors.ImageSharp.Formats.Gif
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
this.configuration = image.GetConfiguration();
ImageMetadata metadata = image.Metadata; ImageMetadata metadata = image.Metadata;
GifMetadata gifMetadata = metadata.GetGifMetadata(); GifMetadata gifMetadata = metadata.GetGifMetadata();
this.colorTableMode = this.colorTableMode ?? gifMetadata.ColorTableMode; this.colorTableMode ??= gifMetadata.ColorTableMode;
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global; bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;
// Quantize the image returning a palette. // Quantize the image returning a palette.
IQuantizedFrame<TPixel> quantized; IQuantizedFrame<TPixel> quantized;
using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(image.GetConfiguration())) using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration))
{ {
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame); quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame);
} }
@ -146,7 +145,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
else else
{ {
using (IFrameQuantizer<TPixel> paletteFrameQuantizer = using (IFrameQuantizer<TPixel> paletteFrameQuantizer =
new PaletteFrameQuantizer<TPixel>(this.quantizer.Diffuser, quantized.Palette)) new PaletteFrameQuantizer<TPixel>(this.configuration, this.quantizer.Diffuser, quantized.Palette))
{ {
using (IQuantizedFrame<TPixel> paletteQuantized = paletteFrameQuantizer.QuantizeFrame(frame)) using (IQuantizedFrame<TPixel> paletteQuantized = paletteFrameQuantizer.QuantizeFrame(frame))
{ {
@ -172,14 +171,14 @@ namespace SixLabors.ImageSharp.Formats.Gif
if (previousFrame != null && previousMeta.ColorTableLength != frameMetadata.ColorTableLength if (previousFrame != null && previousMeta.ColorTableLength != frameMetadata.ColorTableLength
&& frameMetadata.ColorTableLength > 0) && frameMetadata.ColorTableLength > 0)
{ {
using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(image.GetConfiguration(), frameMetadata.ColorTableLength)) using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration, frameMetadata.ColorTableLength))
{ {
quantized = frameQuantizer.QuantizeFrame(frame); quantized = frameQuantizer.QuantizeFrame(frame);
} }
} }
else else
{ {
using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(image.GetConfiguration())) using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration))
{ {
quantized = frameQuantizer.QuantizeFrame(frame); quantized = frameQuantizer.QuantizeFrame(frame);
} }
@ -202,9 +201,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// Returns the index of the most transparent color in the palette. /// Returns the index of the most transparent color in the palette.
/// </summary> /// </summary>
/// <param name="quantized"> /// <param name="quantized">The quantized frame.</param>
/// The quantized.
/// </param>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns> /// <returns>
/// The <see cref="int"/>. /// The <see cref="int"/>.

8
src/ImageSharp/Formats/Jpeg/Components/Encoder/YCbCrForwardConverter{TPixel}.cs

@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
this.pixelBlock.LoadAndStretchEdges(frame, x, y); this.pixelBlock.LoadAndStretchEdges(frame, x, y);
Span<Rgb24> rgbSpan = this.rgbBlock.AsSpanUnsafe(); Span<Rgb24> rgbSpan = this.rgbBlock.AsSpanUnsafe();
PixelOperations<TPixel>.Instance.ToRgb24(frame.Configuration, this.pixelBlock.AsSpanUnsafe(), rgbSpan); PixelOperations<TPixel>.Instance.ToRgb24(frame.GetConfiguration(), this.pixelBlock.AsSpanUnsafe(), rgbSpan);
ref float yBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Y); ref float yBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Y);
ref float cbBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Cb); ref float cbBlockStart = ref Unsafe.As<Block8x8F, float>(ref this.Cb);
@ -81,4 +81,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
} }
} }
} }
} }

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -144,8 +144,8 @@ namespace SixLabors.ImageSharp.Formats.Png
this.height = image.Height; this.height = image.Height;
ImageMetadata metadata = image.Metadata; ImageMetadata metadata = image.Metadata;
PngMetadata pngMetadata = metadata.GetFormatMetadata(PngFormat.Instance); PngMetadata pngMetadata = metadata.GetPngMetadata();
PngEncoderOptionsHelpers.AdjustOptions(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel); PngEncoderOptionsHelpers.AdjustOptions<TPixel>(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel);
IQuantizedFrame<TPixel> quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, image); IQuantizedFrame<TPixel> quantized = PngEncoderOptionsHelpers.CreateQuantizedFrame(this.options, image);
this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, image, quantized); this.bitDepth = PngEncoderOptionsHelpers.CalculateBitDepth(this.options, image, quantized);

89
src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs

@ -14,23 +14,28 @@ namespace SixLabors.ImageSharp.Formats.Png
internal static class PngEncoderOptionsHelpers internal static class PngEncoderOptionsHelpers
{ {
/// <summary> /// <summary>
/// Adjusts the options. /// Adjusts the options based upon the given metadata.
/// </summary> /// </summary>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pngMetadata">The PNG metadata.</param> /// <param name="pngMetadata">The PNG metadata.</param>
/// <param name="use16Bit">if set to <c>true</c> [use16 bit].</param> /// <param name="use16Bit">if set to <c>true</c> [use16 bit].</param>
/// <param name="bytesPerPixel">The bytes per pixel.</param> /// <param name="bytesPerPixel">The bytes per pixel.</param>
public static void AdjustOptions( public static void AdjustOptions<TPixel>(
PngEncoderOptions options, PngEncoderOptions options,
PngMetadata pngMetadata, PngMetadata pngMetadata,
out bool use16Bit, out bool use16Bit,
out int bytesPerPixel) out int bytesPerPixel)
where TPixel : struct, IPixel<TPixel>
{ {
// Always take the encoder options over the metadata values. // Always take the encoder options over the metadata values.
options.Gamma = options.Gamma ?? pngMetadata.Gamma; options.Gamma ??= pngMetadata.Gamma;
options.ColorType = options.ColorType ?? pngMetadata.ColorType;
options.BitDepth = options.BitDepth ?? pngMetadata.BitDepth; // Use options, then check metadata, if nothing set there then we suggest
options.InterlaceMethod = options.InterlaceMethod ?? pngMetadata.InterlaceMethod; // a sensible default based upon the pixel format.
options.ColorType ??= pngMetadata.ColorType ?? SuggestColorType<TPixel>();
options.BitDepth ??= pngMetadata.BitDepth ?? SuggestBitDepth<TPixel>();
options.InterlaceMethod ??= pngMetadata.InterlaceMethod;
use16Bit = options.BitDepth == PngBitDepth.Bit16; use16Bit = options.BitDepth == PngBitDepth.Bit16;
bytesPerPixel = CalculateBytesPerPixel(options.ColorType, use16Bit); bytesPerPixel = CalculateBytesPerPixel(options.ColorType, use16Bit);
@ -129,24 +134,68 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <returns>Bytes per pixel.</returns> /// <returns>Bytes per pixel.</returns>
private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16Bit) private static int CalculateBytesPerPixel(PngColorType? pngColorType, bool use16Bit)
{ {
switch (pngColorType) return pngColorType switch
{ {
case PngColorType.Grayscale: PngColorType.Grayscale => use16Bit ? 2 : 1,
return use16Bit ? 2 : 1; PngColorType.GrayscaleWithAlpha => use16Bit ? 4 : 2,
PngColorType.Palette => 1,
PngColorType.Rgb => use16Bit ? 6 : 3,
case PngColorType.GrayscaleWithAlpha: // PngColorType.RgbWithAlpha
return use16Bit ? 4 : 2; _ => use16Bit ? 8 : 4,
};
case PngColorType.Palette: }
return 1;
case PngColorType.Rgb: /// <summary>
return use16Bit ? 6 : 3; /// Returns a suggested <see cref="PngColorType"/> for the given <typeparamref name="TPixel"/>
/// This is not exhaustive but covers many common pixel formats.
/// </summary>
private static PngColorType SuggestColorType<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
return typeof(TPixel) switch
{
Type t when t == typeof(A8) => PngColorType.GrayscaleWithAlpha,
Type t when t == typeof(Argb32) => PngColorType.RgbWithAlpha,
Type t when t == typeof(Bgr24) => PngColorType.Rgb,
Type t when t == typeof(Bgra32) => PngColorType.RgbWithAlpha,
Type t when t == typeof(L8) => PngColorType.Grayscale,
Type t when t == typeof(L16) => PngColorType.Grayscale,
Type t when t == typeof(La16) => PngColorType.GrayscaleWithAlpha,
Type t when t == typeof(La32) => PngColorType.GrayscaleWithAlpha,
Type t when t == typeof(Rgb24) => PngColorType.Rgb,
Type t when t == typeof(Rgba32) => PngColorType.RgbWithAlpha,
Type t when t == typeof(Rgb48) => PngColorType.Rgb,
Type t when t == typeof(Rgba64) => PngColorType.RgbWithAlpha,
Type t when t == typeof(RgbaVector) => PngColorType.RgbWithAlpha,
_ => PngColorType.RgbWithAlpha
};
}
// PngColorType.RgbWithAlpha /// <summary>
default: /// Returns a suggested <see cref="PngBitDepth"/> for the given <typeparamref name="TPixel"/>
return use16Bit ? 8 : 4; /// This is not exhaustive but covers many common pixel formats.
} /// </summary>
private static PngBitDepth SuggestBitDepth<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
return typeof(TPixel) switch
{
Type t when t == typeof(A8) => PngBitDepth.Bit8,
Type t when t == typeof(Argb32) => PngBitDepth.Bit8,
Type t when t == typeof(Bgr24) => PngBitDepth.Bit8,
Type t when t == typeof(Bgra32) => PngBitDepth.Bit8,
Type t when t == typeof(L8) => PngBitDepth.Bit8,
Type t when t == typeof(L16) => PngBitDepth.Bit16,
Type t when t == typeof(La16) => PngBitDepth.Bit8,
Type t when t == typeof(La32) => PngBitDepth.Bit16,
Type t when t == typeof(Rgb24) => PngBitDepth.Bit8,
Type t when t == typeof(Rgba32) => PngBitDepth.Bit8,
Type t when t == typeof(Rgb48) => PngBitDepth.Bit16,
Type t when t == typeof(Rgba64) => PngBitDepth.Bit16,
Type t when t == typeof(RgbaVector) => PngBitDepth.Bit16,
_ => PngBitDepth.Bit8
};
} }
} }
} }

4
src/ImageSharp/Formats/Png/PngMetadata.cs

@ -44,12 +44,12 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets or sets the number of bits per sample or per palette index (not per pixel). /// Gets or sets the number of bits per sample or per palette index (not per pixel).
/// Not all values are allowed for all <see cref="ColorType"/> values. /// Not all values are allowed for all <see cref="ColorType"/> values.
/// </summary> /// </summary>
public PngBitDepth BitDepth { get; set; } = PngBitDepth.Bit8; public PngBitDepth? BitDepth { get; set; }
/// <summary> /// <summary>
/// Gets or sets the color type. /// Gets or sets the color type.
/// </summary> /// </summary>
public PngColorType ColorType { get; set; } = PngColorType.RgbWithAlpha; public PngColorType? ColorType { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image. /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.

22
src/ImageSharp/Image.cs

@ -16,20 +16,23 @@ namespace SixLabors.ImageSharp
/// For the non-generic <see cref="Image"/> type, the pixel type is only known at runtime. /// For the non-generic <see cref="Image"/> type, the pixel type is only known at runtime.
/// <see cref="Image"/> is always implemented by a pixel-specific <see cref="Image{TPixel}"/> instance. /// <see cref="Image"/> is always implemented by a pixel-specific <see cref="Image{TPixel}"/> instance.
/// </summary> /// </summary>
public abstract partial class Image : IImage, IConfigurable public abstract partial class Image : IImage, IConfigurationProvider
{ {
private Size size; private Size size;
private readonly Configuration configuration;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class. /// Initializes a new instance of the <see cref="Image"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The <see cref="Configuration"/>.</param> /// <param name="configuration">
/// The configuration which allows altering default behaviour or extending the library.
/// </param>
/// <param name="pixelType">The <see cref="PixelTypeInfo"/>.</param> /// <param name="pixelType">The <see cref="PixelTypeInfo"/>.</param>
/// <param name="metadata">The <see cref="ImageMetadata"/>.</param> /// <param name="metadata">The <see cref="ImageMetadata"/>.</param>
/// <param name="size">The <see cref="size"/>.</param> /// <param name="size">The <see cref="size"/>.</param>
protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size) protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
{ {
this.Configuration = configuration ?? Configuration.Default; this.configuration = configuration ?? Configuration.Default;
this.PixelType = pixelType; this.PixelType = pixelType;
this.size = size; this.size = size;
this.Metadata = metadata ?? new ImageMetadata(); this.Metadata = metadata ?? new ImageMetadata();
@ -48,11 +51,6 @@ namespace SixLabors.ImageSharp
{ {
} }
/// <summary>
/// Gets the <see cref="Configuration"/>.
/// </summary>
protected Configuration Configuration { get; }
/// <summary> /// <summary>
/// Gets the <see cref="ImageFrameCollection"/> implementing the public <see cref="Frames"/> property. /// Gets the <see cref="ImageFrameCollection"/> implementing the public <see cref="Frames"/> property.
/// </summary> /// </summary>
@ -75,10 +73,8 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public ImageFrameCollection Frames => this.NonGenericFrameCollection; public ImageFrameCollection Frames => this.NonGenericFrameCollection;
/// <summary> /// <inheritdoc/>
/// Gets the pixel buffer. Configuration IConfigurationProvider.Configuration => this.configuration;
/// </summary>
Configuration IConfigurable.Configuration => this.Configuration;
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
@ -108,7 +104,7 @@ namespace SixLabors.ImageSharp
/// <typeparam name="TPixel2">The pixel format.</typeparam> /// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="Image{TPixel2}"/></returns> /// <returns>The <see cref="Image{TPixel2}"/></returns>
public Image<TPixel2> CloneAs<TPixel2>() public Image<TPixel2> CloneAs<TPixel2>()
where TPixel2 : struct, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.Configuration); where TPixel2 : struct, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.GetConfiguration());
/// <summary> /// <summary>
/// Returns a copy of the image in the given pixel format. /// Returns a copy of the image in the given pixel format.

28
src/ImageSharp/ImageFrame.cs

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -13,37 +13,28 @@ namespace SixLabors.ImageSharp
/// In case of animated formats like gif, it contains the single frame in a animation. /// In case of animated formats like gif, it contains the single frame in a animation.
/// In all other cases it is the only frame of the image. /// In all other cases it is the only frame of the image.
/// </summary> /// </summary>
public abstract partial class ImageFrame : IDisposable public abstract partial class ImageFrame : IConfigurationProvider, IDisposable
{ {
private readonly Configuration configuration;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame"/> class. /// Initializes a new instance of the <see cref="ImageFrame"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The <see cref="Configuration"/>.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="width">The width.</param> /// <param name="width">The frame width.</param>
/// <param name="height">The height.</param> /// <param name="height">The frame height.</param>
/// <param name="metadata">The <see cref="ImageFrameMetadata"/>.</param> /// <param name="metadata">The <see cref="ImageFrameMetadata"/>.</param>
protected ImageFrame(Configuration configuration, int width, int height, ImageFrameMetadata metadata) protected ImageFrame(Configuration configuration, int width, int height, ImageFrameMetadata metadata)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(metadata, nameof(metadata)); Guard.NotNull(metadata, nameof(metadata));
this.Configuration = configuration; this.configuration = configuration ?? Configuration.Default;
this.MemoryAllocator = configuration.MemoryAllocator;
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
this.Metadata = metadata; this.Metadata = metadata;
} }
/// <summary>
/// Gets the <see cref="MemoryAllocator" /> to use for buffer allocations.
/// </summary>
public MemoryAllocator MemoryAllocator { get; }
/// <summary>
/// Gets the <see cref="Configuration"/> instance associated with this <see cref="ImageFrame{TPixel}"/>.
/// </summary>
internal Configuration Configuration { get; }
/// <summary> /// <summary>
/// Gets the width. /// Gets the width.
/// </summary> /// </summary>
@ -59,6 +50,9 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public ImageFrameMetadata Metadata { get; } public ImageFrameMetadata Metadata { get; }
/// <inheritdoc/>
Configuration IConfigurationProvider.Configuration => this.configuration;
/// <summary> /// <summary>
/// Gets the size of the frame. /// Gets the size of the frame.
/// </summary> /// </summary>

12
src/ImageSharp/ImageFrame{TPixel}.cs

@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height)); Guard.MustBeGreaterThan(height, 0, nameof(height));
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(width, height, AllocationOptions.Clean); this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D<TPixel>(width, height, AllocationOptions.Clean);
} }
/// <summary> /// <summary>
@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height)); Guard.MustBeGreaterThan(height, 0, nameof(height));
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(width, height); this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D<TPixel>(width, height);
this.Clear(backgroundColor); this.Clear(backgroundColor);
} }
@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
this.PixelBuffer = this.MemoryAllocator.Allocate2D<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height); this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height);
source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan()); source.PixelBuffer.GetSpan().CopyTo(this.PixelBuffer.GetSpan());
} }
@ -219,7 +219,7 @@ namespace SixLabors.ImageSharp
this.PixelBuffer.GetSpan().CopyTo(dest1); this.PixelBuffer.GetSpan().CopyTo(dest1);
} }
PixelOperations<TPixel>.Instance.To(this.Configuration, this.PixelBuffer.GetSpan(), destination); PixelOperations<TPixel>.Instance.To(this.GetConfiguration(), this.PixelBuffer.GetSpan(), destination);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -229,7 +229,7 @@ namespace SixLabors.ImageSharp
/// Clones the current instance. /// Clones the current instance.
/// </summary> /// </summary>
/// <returns>The <see cref="ImageFrame{TPixel}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal ImageFrame<TPixel> Clone() => this.Clone(this.Configuration); internal ImageFrame<TPixel> Clone() => this.Clone(this.GetConfiguration());
/// <summary> /// <summary>
/// Clones the current instance. /// Clones the current instance.
@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp
/// <typeparam name="TPixel2">The pixel format.</typeparam> /// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="ImageFrame{TPixel2}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
internal ImageFrame<TPixel2> CloneAs<TPixel2>() internal ImageFrame<TPixel2> CloneAs<TPixel2>()
where TPixel2 : struct, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.Configuration); where TPixel2 : struct, IPixel<TPixel2> => this.CloneAs<TPixel2>(this.GetConfiguration());
/// <summary> /// <summary>
/// Returns a copy of the image frame in the given pixel format. /// Returns a copy of the image frame in the given pixel format.

2
src/ImageSharp/Image{TPixel}.cs

@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp
/// Clones the current image /// Clones the current image
/// </summary> /// </summary>
/// <returns>Returns a new image with all the same metadata as the original.</returns> /// <returns>Returns a new image with all the same metadata as the original.</returns>
public Image<TPixel> Clone() => this.Clone(this.Configuration); public Image<TPixel> Clone() => this.Clone(this.GetConfiguration());
/// <summary> /// <summary>
/// Clones the current image with the given configuration. /// Clones the current image with the given configuration.

2
src/ImageSharp/Metadata/Profiles/Exif/ExifTags.cs

@ -225,7 +225,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
case ExifTagValue.ImageUniqueID: case ExifTagValue.ImageUniqueID:
case ExifTagValue.OwnerName: case ExifTagValue.OwnerName:
case ExifTagValue.SerialNumber: case ExifTagValue.SerialNumber:
case ExifTagValue.LensInfo: case ExifTagValue.LensSpecification:
case ExifTagValue.LensMake: case ExifTagValue.LensMake:
case ExifTagValue.LensModel: case ExifTagValue.LensModel:
case ExifTagValue.LensSerialNumber: case ExifTagValue.LensSerialNumber:

5
src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.Rational.cs

@ -131,11 +131,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
/// </summary> /// </summary>
public static ExifTag<Rational> DigitalZoomRatio { get; } = new ExifTag<Rational>(ExifTagValue.DigitalZoomRatio); public static ExifTag<Rational> DigitalZoomRatio { get; } = new ExifTag<Rational>(ExifTagValue.DigitalZoomRatio);
/// <summary>
/// Gets the LensInfo exif tag.
/// </summary>
public static ExifTag<Rational> LensInfo { get; } = new ExifTag<Rational>(ExifTagValue.LensInfo);
/// <summary> /// <summary>
/// Gets the GPSAltitude exif tag. /// Gets the GPSAltitude exif tag.
/// </summary> /// </summary>

5
src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTag.RationalArray.cs

@ -50,5 +50,10 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
/// Gets the GPSDestLongitude exif tag. /// Gets the GPSDestLongitude exif tag.
/// </summary> /// </summary>
public static ExifTag<Rational[]> GPSDestLongitude { get; } = new ExifTag<Rational[]>(ExifTagValue.GPSDestLongitude); public static ExifTag<Rational[]> GPSDestLongitude { get; } = new ExifTag<Rational[]>(ExifTagValue.GPSDestLongitude);
/// <summary>
/// Gets the LensSpecification exif tag.
/// </summary>
public static ExifTag<Rational[]> LensSpecification { get; } = new ExifTag<Rational[]>(ExifTagValue.LensSpecification);
} }
} }

4
src/ImageSharp/Metadata/Profiles/Exif/Tags/ExifTagValue.cs

@ -1356,9 +1356,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
SerialNumber = 0xA431, SerialNumber = 0xA431,
/// <summary> /// <summary>
/// LensInfo /// LensSpecification
/// </summary> /// </summary>
LensInfo = 0xA432, LensSpecification = 0xA432,
/// <summary> /// <summary>
/// LensMake /// LensMake

2
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs

@ -129,7 +129,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
case ExifTagValue.FocalPlaneYResolution: return new ExifRational(ExifTag.FocalPlaneYResolution); case ExifTagValue.FocalPlaneYResolution: return new ExifRational(ExifTag.FocalPlaneYResolution);
case ExifTagValue.ExposureIndex: return new ExifRational(ExifTag.ExposureIndex); case ExifTagValue.ExposureIndex: return new ExifRational(ExifTag.ExposureIndex);
case ExifTagValue.DigitalZoomRatio: return new ExifRational(ExifTag.DigitalZoomRatio); case ExifTagValue.DigitalZoomRatio: return new ExifRational(ExifTag.DigitalZoomRatio);
case ExifTagValue.LensInfo: return new ExifRational(ExifTag.LensInfo);
case ExifTagValue.GPSAltitude: return new ExifRational(ExifTag.GPSAltitude); case ExifTagValue.GPSAltitude: return new ExifRational(ExifTag.GPSAltitude);
case ExifTagValue.GPSDOP: return new ExifRational(ExifTag.GPSDOP); case ExifTagValue.GPSDOP: return new ExifRational(ExifTag.GPSDOP);
case ExifTagValue.GPSSpeed: return new ExifRational(ExifTag.GPSSpeed); case ExifTagValue.GPSSpeed: return new ExifRational(ExifTag.GPSSpeed);
@ -147,6 +146,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
case ExifTagValue.GPSTimestamp: return new ExifRationalArray(ExifTag.GPSTimestamp); case ExifTagValue.GPSTimestamp: return new ExifRationalArray(ExifTag.GPSTimestamp);
case ExifTagValue.GPSDestLatitude: return new ExifRationalArray(ExifTag.GPSDestLatitude); case ExifTagValue.GPSDestLatitude: return new ExifRationalArray(ExifTag.GPSDestLatitude);
case ExifTagValue.GPSDestLongitude: return new ExifRationalArray(ExifTag.GPSDestLongitude); case ExifTagValue.GPSDestLongitude: return new ExifRationalArray(ExifTag.GPSDestLongitude);
case ExifTagValue.LensSpecification: return new ExifRationalArray(ExifTag.LensSpecification);
case ExifTagValue.OldSubfileType: return new ExifShort(ExifTag.OldSubfileType); case ExifTagValue.OldSubfileType: return new ExifShort(ExifTag.OldSubfileType);
case ExifTagValue.Compression: return new ExifShort(ExifTag.Compression); case ExifTagValue.Compression: return new ExifShort(ExifTag.Compression);

3
src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{ {
@ -53,4 +54,4 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
return this.Equals((IccTagDataEntry)other); return this.Equals((IccTagDataEntry)other);
} }
} }
} }

98
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,27 +24,27 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Argb32> internal class PixelOperations : PixelOperations<Argb32>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<Argb32> destPixels) public override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Argb32> destPixels, PixelConversionModifiers modifiers) public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Argb32> destinationPixels, PixelConversionModifiers modifiers)
{ {
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale)); Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -54,13 +53,13 @@ namespace SixLabors.ImageSharp.PixelFormats
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -70,13 +69,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Argb32> destPixels) public override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -85,13 +84,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -101,13 +100,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Argb32> destPixels) public override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -117,13 +116,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -135,13 +134,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -153,13 +152,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -171,13 +170,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -189,13 +188,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -207,13 +206,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -225,13 +224,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -243,13 +242,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -261,13 +260,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -278,14 +277,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Argb32> destinationPixels) Span<Argb32> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

86
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,27 +24,27 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Bgr24> internal class PixelOperations : PixelOperations<Bgr24>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<Bgr24> destPixels) public override void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgr24> destPixels, PixelConversionModifiers modifiers) public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgr24> destinationPixels, PixelConversionModifiers modifiers)
{ {
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -55,13 +54,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -73,13 +72,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -91,13 +90,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -109,13 +108,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -127,13 +126,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -145,13 +144,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -163,13 +162,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -181,13 +180,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -199,13 +198,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -217,13 +216,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -235,13 +234,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgr24> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -252,14 +251,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgr24> destinationPixels) Span<Bgr24> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

98
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,27 +24,27 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Bgra32> internal class PixelOperations : PixelOperations<Bgra32>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<Bgra32> destPixels) public override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgra32> destPixels, PixelConversionModifiers modifiers) public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgra32> destinationPixels, PixelConversionModifiers modifiers)
{ {
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale)); Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -54,13 +53,13 @@ namespace SixLabors.ImageSharp.PixelFormats
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -70,13 +69,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra32> destPixels) public override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -85,13 +84,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -101,13 +100,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra32> destPixels) public override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -117,13 +116,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -135,13 +134,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -153,13 +152,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -171,13 +170,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -189,13 +188,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -207,13 +206,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -225,13 +224,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -243,13 +242,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -261,13 +260,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -278,14 +277,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgra32> destinationPixels) Span<Bgra32> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

80
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra5551.PixelOperations.Generated.cs

@ -24,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Bgra5551> internal class PixelOperations : PixelOperations<Bgra5551>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<Bgra5551> destPixels) public override void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -79,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -97,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -133,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -169,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -187,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -205,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -223,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Bgra5551> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgra5551> destinationPixels) Span<Bgra5551> destinationPixels)

80
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L16.PixelOperations.Generated.cs

@ -24,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<L16> internal class PixelOperations : PixelOperations<L16>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromL16(Configuration configuration, ReadOnlySpan<L16> source, Span<L16> destPixels) public override void FromL16(Configuration configuration, ReadOnlySpan<L16> source, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -79,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -97,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -133,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -169,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -187,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -205,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -223,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<L16> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<L16> destinationPixels) Span<L16> destinationPixels)

80
src/ImageSharp/PixelFormats/PixelImplementations/Generated/L8.PixelOperations.Generated.cs

@ -24,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<L8> internal class PixelOperations : PixelOperations<L8>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromL8(Configuration configuration, ReadOnlySpan<L8> source, Span<L8> destPixels) public override void FromL8(Configuration configuration, ReadOnlySpan<L8> source, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -79,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -97,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -133,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -169,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -187,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -205,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -223,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<L8> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<L8> destinationPixels) Span<L8> destinationPixels)

80
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La16.PixelOperations.Generated.cs

@ -24,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<La16> internal class PixelOperations : PixelOperations<La16>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromLa16(Configuration configuration, ReadOnlySpan<La16> source, Span<La16> destPixels) public override void FromLa16(Configuration configuration, ReadOnlySpan<La16> source, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -79,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -97,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -133,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -169,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -187,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -205,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -223,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<La16> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<La16> destinationPixels) Span<La16> destinationPixels)

80
src/ImageSharp/PixelFormats/PixelImplementations/Generated/La32.PixelOperations.Generated.cs

@ -24,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<La32> internal class PixelOperations : PixelOperations<La32>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromLa32(Configuration configuration, ReadOnlySpan<La32> source, Span<La32> destPixels) public override void FromLa32(Configuration configuration, ReadOnlySpan<La32> source, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -79,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -97,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -115,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -133,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -151,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -169,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -187,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -205,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -223,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<La32> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<La32> destinationPixels) Span<La32> destinationPixels)

86
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,27 +24,27 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Rgb24> internal class PixelOperations : PixelOperations<Rgb24>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<Rgb24> destPixels) public override void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Rgb24> destPixels, PixelConversionModifiers modifiers) public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Rgb24> destinationPixels, PixelConversionModifiers modifiers)
{ {
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -55,13 +54,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -73,13 +72,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -91,13 +90,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -109,13 +108,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -127,13 +126,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -145,13 +144,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -163,13 +162,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -181,13 +180,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -199,13 +198,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -217,13 +216,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -235,13 +234,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb24> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -252,14 +251,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgb24> destinationPixels) Span<Rgb24> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToRgb24(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToRgb24(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

82
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb48.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Rgb48> internal class PixelOperations : PixelOperations<Rgb48>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<Rgb48> destPixels) public override void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -62,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -80,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -98,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -116,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -134,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -152,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -170,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -188,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -206,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -224,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgb48> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -241,14 +240,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgb48> destinationPixels) Span<Rgb48> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToRgb48(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToRgb48(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

94
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba32.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,31 +24,31 @@ namespace SixLabors.ImageSharp.PixelFormats
internal partial class PixelOperations : PixelOperations<Rgba32> internal partial class PixelOperations : PixelOperations<Rgba32>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<Rgba32> destPixels) public override void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Argb32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -59,13 +58,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba32> destPixels) public override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Argb32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -74,13 +73,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Rgba32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Bgra32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -90,13 +89,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba32> destPixels) public override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<Bgra32,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -106,13 +105,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -124,13 +123,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -142,13 +141,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -160,13 +159,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -178,13 +177,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -196,13 +195,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -214,13 +213,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -232,13 +231,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -250,13 +249,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba32> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -267,14 +266,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgba32> destinationPixels) Span<Rgba32> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToRgba32(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToRgba32(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

82
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgba64.PixelOperations.Generated.cs

@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <content> /// <content>
@ -25,32 +24,32 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<Rgba64> internal class PixelOperations : PixelOperations<Rgba64>
{ {
/// <inheritdoc /> /// <inheritdoc />
internal override void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<Rgba64> destPixels) public override void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgba64> destPixels) public override void ToRgba64(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Argb32> destPixels) public override void ToArgb32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -62,13 +61,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgr24> destPixels) public override void ToBgr24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -80,13 +79,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra32> destPixels) public override void ToBgra32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -98,13 +97,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL8(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -116,13 +115,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToL16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -134,13 +133,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La16> destPixels) public override void ToLa16(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -152,13 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La32> destPixels) public override void ToLa32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -170,13 +169,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb24> destPixels) public override void ToRgb24(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -188,13 +187,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgba32> destPixels) public override void ToRgba32(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -206,13 +205,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb48> destPixels) public override void ToRgb48(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -224,13 +223,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra5551> destPixels) public override void ToBgra5551(Configuration configuration, ReadOnlySpan<Rgba64> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -241,14 +240,13 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Rgba64> destinationPixels) Span<Rgba64> destinationPixels)
{ {
PixelOperations<TSourcePixel>.Instance.ToRgba64(configuration, sourcePixels, destinationPixels); PixelOperations<TSourcePixel>.Instance.ToRgba64(configuration, sourcePixels, destinationPixels);
} }
} }
} }
} }

36
src/ImageSharp/PixelFormats/PixelImplementations/Generated/_Common.ttinclude

@ -26,7 +26,7 @@ using System.Runtime.InteropServices;
{ {
#> #>
/// <inheritdoc /> /// <inheritdoc />
internal override void From<TSourcePixel>( public override void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<<#=pixelType#>> destinationPixels) Span<<#=pixelType#>> destinationPixels)
@ -40,21 +40,21 @@ using System.Runtime.InteropServices;
{ {
#> #>
/// <inheritdoc /> /// <inheritdoc />
internal override void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<<#=pixelType#>> destPixels) public override void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<<#=pixelType#>> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destPixels); source.CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void To<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> sourcePixels, Span<<#=pixelType#>> destPixels) public override void To<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> sourcePixels, Span<<#=pixelType#>> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destPixels); sourcePixels.CopyTo(destinationPixels);
} }
<#+ <#+
@ -65,13 +65,13 @@ using System.Runtime.InteropServices;
#> #>
/// <inheritdoc /> /// <inheritdoc />
internal override void To<#=toPixelType#>(Configuration configuration, ReadOnlySpan<<#=fromPixelType#>> sourcePixels, Span<<#=toPixelType#>> destPixels) public override void To<#=toPixelType#>(Configuration configuration, ReadOnlySpan<<#=fromPixelType#>> sourcePixels, Span<<#=toPixelType#>> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destPixels); ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -88,13 +88,13 @@ using System.Runtime.InteropServices;
{ {
#> #>
/// <inheritdoc /> /// <inheritdoc />
internal override void To<#=otherPixelType#>(Configuration configuration, ReadOnlySpan<<#=thisPixelType#>> sourcePixels, Span<<#=otherPixelType#>> destPixels) public override void To<#=otherPixelType#>(Configuration configuration, ReadOnlySpan<<#=thisPixelType#>> sourcePixels, Span<<#=otherPixelType#>> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<<#=thisPixelType#>,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<<#=thisPixelType#>,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<<#=otherPixelType#>, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<<#=otherPixelType#>, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -104,13 +104,13 @@ using System.Runtime.InteropServices;
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void From<#=otherPixelType#>(Configuration configuration, ReadOnlySpan<<#=otherPixelType#>> sourcePixels, Span<<#=thisPixelType#>> destPixels) public override void From<#=otherPixelType#>(Configuration configuration, ReadOnlySpan<<#=otherPixelType#>> sourcePixels, Span<<#=thisPixelType#>> destinationPixels)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref uint sourceRef = ref Unsafe.As<<#=otherPixelType#>,uint>(ref MemoryMarshal.GetReference(sourcePixels)); ref uint sourceRef = ref Unsafe.As<<#=otherPixelType#>,uint>(ref MemoryMarshal.GetReference(sourcePixels));
ref uint destRef = ref Unsafe.As<<#=thisPixelType#>, uint>(ref MemoryMarshal.GetReference(destPixels)); ref uint destRef = ref Unsafe.As<<#=thisPixelType#>, uint>(ref MemoryMarshal.GetReference(destinationPixels));
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -130,9 +130,9 @@ using System.Runtime.InteropServices;
} }
#> #>
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<<#=pixelType#>> destPixels, PixelConversionModifiers modifiers) public override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<<#=pixelType#>> destinationPixels, PixelConversionModifiers modifiers)
{ {
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(<#=removeTheseModifiers#>)); Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(<#=removeTheseModifiers#>));
} }
/// <inheritdoc /> /// <inheritdoc />

18
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs

@ -23,32 +23,32 @@ namespace SixLabors.ImageSharp.PixelFormats
public override void ToVector4( public override void ToVector4(
Configuration configuration, Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels, ReadOnlySpan<Rgba32> sourcePixels,
Span<Vector4> destVectors, Span<Vector4> destinationVectors,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destVectors, nameof(destVectors)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationVectors, nameof(destinationVectors));
destVectors = destVectors.Slice(0, sourcePixels.Length); destinationVectors = destinationVectors.Slice(0, sourcePixels.Length);
SimdUtils.BulkConvertByteToNormalizedFloat( SimdUtils.BulkConvertByteToNormalizedFloat(
MemoryMarshal.Cast<Rgba32, byte>(sourcePixels), MemoryMarshal.Cast<Rgba32, byte>(sourcePixels),
MemoryMarshal.Cast<Vector4, float>(destVectors)); MemoryMarshal.Cast<Vector4, float>(destinationVectors));
Vector4Converters.ApplyForwardConversionModifiers(destVectors, modifiers); Vector4Converters.ApplyForwardConversionModifiers(destinationVectors, modifiers);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void FromVector4Destructive( public override void FromVector4Destructive(
Configuration configuration, Configuration configuration,
Span<Vector4> sourceVectors, Span<Vector4> sourceVectors,
Span<Rgba32> destPixels, Span<Rgba32> destinationPixels,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.DestinationShouldNotBeTooShort(sourceVectors, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourceVectors, destinationPixels, nameof(destinationPixels));
destPixels = destPixels.Slice(0, sourceVectors.Length); destinationPixels = destinationPixels.Slice(0, sourceVectors.Length);
Vector4Converters.ApplyBackwardConversionModifiers(sourceVectors, modifiers); Vector4Converters.ApplyBackwardConversionModifiers(sourceVectors, modifiers);
SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows( SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(
MemoryMarshal.Cast<Vector4, float>(sourceVectors), MemoryMarshal.Cast<Vector4, float>(sourceVectors),
MemoryMarshal.Cast<Rgba32, byte>(destPixels)); MemoryMarshal.Cast<Rgba32, byte>(destinationPixels));
} }
} }
} }

26
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs

@ -24,34 +24,34 @@ namespace SixLabors.ImageSharp.PixelFormats
public override void FromVector4Destructive( public override void FromVector4Destructive(
Configuration configuration, Configuration configuration,
Span<Vector4> sourceVectors, Span<Vector4> sourceVectors,
Span<RgbaVector> destinationColors, Span<RgbaVector> destinationPixels,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.DestinationShouldNotBeTooShort(sourceVectors, destinationColors, nameof(destinationColors)); Guard.DestinationShouldNotBeTooShort(sourceVectors, destinationPixels, nameof(destinationPixels));
Vector4Converters.ApplyBackwardConversionModifiers(sourceVectors, modifiers); Vector4Converters.ApplyBackwardConversionModifiers(sourceVectors, modifiers);
MemoryMarshal.Cast<Vector4, RgbaVector>(sourceVectors).CopyTo(destinationColors); MemoryMarshal.Cast<Vector4, RgbaVector>(sourceVectors).CopyTo(destinationPixels);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ToVector4( public override void ToVector4(
Configuration configuration, Configuration configuration,
ReadOnlySpan<RgbaVector> sourcePixels, ReadOnlySpan<RgbaVector> sourcePixels,
Span<Vector4> destVectors, Span<Vector4> destinationVectors,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destVectors, nameof(destVectors)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationVectors, nameof(destinationVectors));
MemoryMarshal.Cast<RgbaVector, Vector4>(sourcePixels).CopyTo(destVectors); MemoryMarshal.Cast<RgbaVector, Vector4>(sourcePixels).CopyTo(destinationVectors);
Vector4Converters.ApplyForwardConversionModifiers(destVectors, modifiers); Vector4Converters.ApplyForwardConversionModifiers(destinationVectors, modifiers);
} }
internal override void ToL8(Configuration configuration, ReadOnlySpan<RgbaVector> sourcePixels, Span<L8> destPixels) public override void ToL8(Configuration configuration, ReadOnlySpan<RgbaVector> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Vector4 sourceBaseRef = ref Unsafe.As<RgbaVector, Vector4>(ref MemoryMarshal.GetReference(sourcePixels)); ref Vector4 sourceBaseRef = ref Unsafe.As<RgbaVector, Vector4>(ref MemoryMarshal.GetReference(sourcePixels));
ref L8 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -62,12 +62,12 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
} }
internal override void ToL16(Configuration configuration, ReadOnlySpan<RgbaVector> sourcePixels, Span<L16> destPixels) public override void ToL16(Configuration configuration, ReadOnlySpan<RgbaVector> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Vector4 sourceBaseRef = ref Unsafe.As<RgbaVector, Vector4>(ref MemoryMarshal.GetReference(sourcePixels)); ref Vector4 sourceBaseRef = ref Unsafe.As<RgbaVector, Vector4>(ref MemoryMarshal.GetReference(sourcePixels));
ref L16 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {

288
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs

@ -15,13 +15,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Argb32"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Argb32"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<TPixel> destPixels) public virtual void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Argb32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Argb32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -38,12 +38,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromArgb32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromArgb32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromArgb32(configuration, MemoryMarshal.Cast<byte, Argb32>(sourceBytes).Slice(0, count), destPixels); this.FromArgb32(configuration, MemoryMarshal.Cast<byte, Argb32>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -51,13 +51,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Argb32"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Argb32"/> data.</param>
internal virtual void ToArgb32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Argb32> destPixels) public virtual void ToArgb32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Argb32> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Argb32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToArgb32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Argb32>(destBytes)); this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Argb32>(destBytes));
} }
@ -87,13 +87,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgr24"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgr24"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<TPixel> destPixels) public virtual void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Bgr24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Bgr24 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -110,12 +110,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromBgr24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromBgr24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromBgr24(configuration, MemoryMarshal.Cast<byte, Bgr24>(sourceBytes).Slice(0, count), destPixels); this.FromBgr24(configuration, MemoryMarshal.Cast<byte, Bgr24>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -123,13 +123,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Bgr24"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Bgr24"/> data.</param>
internal virtual void ToBgr24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgr24> destPixels) public virtual void ToBgr24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgr24> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToBgr24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToBgr24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgr24>(destBytes)); this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgr24>(destBytes));
} }
@ -159,13 +159,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra32"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra32"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<TPixel> destPixels) public virtual void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Bgra32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Bgra32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -182,12 +182,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromBgra32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromBgra32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromBgra32(configuration, MemoryMarshal.Cast<byte, Bgra32>(sourceBytes).Slice(0, count), destPixels); this.FromBgra32(configuration, MemoryMarshal.Cast<byte, Bgra32>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -195,13 +195,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Bgra32"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Bgra32"/> data.</param>
internal virtual void ToBgra32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra32> destPixels) public virtual void ToBgra32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra32> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -221,7 +221,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToBgra32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToBgra32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra32>(destBytes)); this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra32>(destBytes));
} }
@ -231,13 +231,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="L8"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="L8"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromL8(Configuration configuration, ReadOnlySpan<L8> source, Span<TPixel> destPixels) public virtual void FromL8(Configuration configuration, ReadOnlySpan<L8> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref L8 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref L8 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -254,12 +254,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromL8Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromL8Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromL8(configuration, MemoryMarshal.Cast<byte, L8>(sourceBytes).Slice(0, count), destPixels); this.FromL8(configuration, MemoryMarshal.Cast<byte, L8>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -267,13 +267,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="L8"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="L8"/> data.</param>
internal virtual void ToL8(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<L8> destPixels) public virtual void ToL8(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<L8> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref L8 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -293,7 +293,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToL8Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToL8Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, L8>(destBytes)); this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, L8>(destBytes));
} }
@ -303,13 +303,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="L16"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="L16"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromL16(Configuration configuration, ReadOnlySpan<L16> source, Span<TPixel> destPixels) public virtual void FromL16(Configuration configuration, ReadOnlySpan<L16> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref L16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref L16 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -326,12 +326,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromL16Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromL16Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromL16(configuration, MemoryMarshal.Cast<byte, L16>(sourceBytes).Slice(0, count), destPixels); this.FromL16(configuration, MemoryMarshal.Cast<byte, L16>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -339,13 +339,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="L16"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="L16"/> data.</param>
internal virtual void ToL16(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<L16> destPixels) public virtual void ToL16(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<L16> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref L16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToL16Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToL16Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, L16>(destBytes)); this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, L16>(destBytes));
} }
@ -375,13 +375,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="La16"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="La16"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromLa16(Configuration configuration, ReadOnlySpan<La16> source, Span<TPixel> destPixels) public virtual void FromLa16(Configuration configuration, ReadOnlySpan<La16> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref La16 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref La16 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -398,12 +398,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromLa16Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromLa16Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromLa16(configuration, MemoryMarshal.Cast<byte, La16>(sourceBytes).Slice(0, count), destPixels); this.FromLa16(configuration, MemoryMarshal.Cast<byte, La16>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -411,13 +411,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="La16"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="La16"/> data.</param>
internal virtual void ToLa16(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<La16> destPixels) public virtual void ToLa16(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<La16> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref La16 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -437,7 +437,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToLa16Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToLa16Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, La16>(destBytes)); this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, La16>(destBytes));
} }
@ -447,13 +447,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="La32"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="La32"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromLa32(Configuration configuration, ReadOnlySpan<La32> source, Span<TPixel> destPixels) public virtual void FromLa32(Configuration configuration, ReadOnlySpan<La32> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref La32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref La32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -470,12 +470,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromLa32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromLa32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromLa32(configuration, MemoryMarshal.Cast<byte, La32>(sourceBytes).Slice(0, count), destPixels); this.FromLa32(configuration, MemoryMarshal.Cast<byte, La32>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -483,13 +483,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="La32"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="La32"/> data.</param>
internal virtual void ToLa32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<La32> destPixels) public virtual void ToLa32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<La32> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref La32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -509,7 +509,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToLa32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToLa32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, La32>(destBytes)); this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, La32>(destBytes));
} }
@ -519,13 +519,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb24"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb24"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<TPixel> destPixels) public virtual void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Rgb24 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Rgb24 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -542,12 +542,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromRgb24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromRgb24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromRgb24(configuration, MemoryMarshal.Cast<byte, Rgb24>(sourceBytes).Slice(0, count), destPixels); this.FromRgb24(configuration, MemoryMarshal.Cast<byte, Rgb24>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -555,13 +555,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Rgb24"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Rgb24"/> data.</param>
internal virtual void ToRgb24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb24> destPixels) public virtual void ToRgb24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb24> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -581,7 +581,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgb24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToRgb24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb24>(destBytes)); this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb24>(destBytes));
} }
@ -591,13 +591,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba32"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba32"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<TPixel> destPixels) public virtual void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Rgba32 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Rgba32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -614,12 +614,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromRgba32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromRgba32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromRgba32(configuration, MemoryMarshal.Cast<byte, Rgba32>(sourceBytes).Slice(0, count), destPixels); this.FromRgba32(configuration, MemoryMarshal.Cast<byte, Rgba32>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -627,13 +627,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Rgba32"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Rgba32"/> data.</param>
internal virtual void ToRgba32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba32> destPixels) public virtual void ToRgba32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba32> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -653,7 +653,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgba32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToRgba32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba32>(destBytes)); this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba32>(destBytes));
} }
@ -663,13 +663,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb48"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb48"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<TPixel> destPixels) public virtual void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Rgb48 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -686,12 +686,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromRgb48Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromRgb48Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromRgb48(configuration, MemoryMarshal.Cast<byte, Rgb48>(sourceBytes).Slice(0, count), destPixels); this.FromRgb48(configuration, MemoryMarshal.Cast<byte, Rgb48>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -699,13 +699,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Rgb48"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Rgb48"/> data.</param>
internal virtual void ToRgb48(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb48> destPixels) public virtual void ToRgb48(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb48> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Rgb48 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -725,7 +725,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgb48Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToRgb48Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb48>(destBytes)); this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb48>(destBytes));
} }
@ -735,13 +735,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba64"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba64"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<TPixel> destPixels) public virtual void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Rgba64 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -758,12 +758,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromRgba64Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromRgba64Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromRgba64(configuration, MemoryMarshal.Cast<byte, Rgba64>(sourceBytes).Slice(0, count), destPixels); this.FromRgba64(configuration, MemoryMarshal.Cast<byte, Rgba64>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -771,13 +771,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Rgba64"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Rgba64"/> data.</param>
internal virtual void ToRgba64(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba64> destPixels) public virtual void ToRgba64(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba64> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Rgba64 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -797,7 +797,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToRgba64Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToRgba64Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba64>(destBytes)); this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba64>(destBytes));
} }
@ -807,13 +807,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra5551"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra5551"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<TPixel> destPixels) public virtual void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source); ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -830,12 +830,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.FromBgra5551(configuration, MemoryMarshal.Cast<byte, Bgra5551>(sourceBytes).Slice(0, count), destPixels); this.FromBgra5551(configuration, MemoryMarshal.Cast<byte, Bgra5551>(sourceBytes).Slice(0, count), destinationPixels);
} }
/// <summary> /// <summary>
@ -843,13 +843,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="Bgra5551"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="Bgra5551"/> data.</param>
internal virtual void ToBgra5551(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra5551> destPixels) public virtual void ToBgra5551(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra5551> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -869,7 +869,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra5551>(destBytes)); this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra5551>(destBytes));
} }

24
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt

@ -20,13 +20,13 @@
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> /// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
internal virtual void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels) public virtual void From<#=pixelType#>(Configuration configuration, ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref <#=pixelType#> sourceBaseRef = ref MemoryMarshal.GetReference(source); ref <#=pixelType#> sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++) for (int i = 0; i < source.Length; i++)
{ {
@ -43,12 +43,12 @@
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) public void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{ {
this.From<#=pixelType#>(configuration, MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes).Slice(0, count), destPixels); this.From<#=pixelType#>(configuration, MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes).Slice(0, count), destinationPixels);
} }
<# <#
@ -62,13 +62,13 @@
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param> /// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destPixels">The destination span of <see cref="<#=pixelType#>"/> data.</param> /// <param name="destinationPixels">The destination span of <see cref="<#=pixelType#>"/> data.</param>
internal virtual void To<#=pixelType#>(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<<#=pixelType#>> destPixels) public virtual void To<#=pixelType#>(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<<#=pixelType#>> destinationPixels)
{ {
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(destPixels); ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++) for (int i = 0; i < sourcePixels.Length; i++)
{ {
@ -88,7 +88,7 @@
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count) public void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{ {
this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, <#=pixelType#>>(destBytes)); this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, <#=pixelType#>>(destBytes));
} }

43
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -32,17 +32,17 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </remarks> /// </remarks>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param> /// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination colors.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param> /// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param>
public virtual void FromVector4Destructive( public virtual void FromVector4Destructive(
Configuration configuration, Configuration configuration,
Span<Vector4> sourceVectors, Span<Vector4> sourceVectors,
Span<TPixel> destPixels, Span<TPixel> destinationPixels,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Utils.Vector4Converters.Default.FromVector4(sourceVectors, destPixels, modifiers); Utils.Vector4Converters.Default.FromVector4(sourceVectors, destinationPixels, modifiers);
} }
/// <summary> /// <summary>
@ -55,29 +55,29 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </remarks> /// </remarks>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param> /// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param> /// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination colors.</param>
public void FromVector4Destructive( public void FromVector4Destructive(
Configuration configuration, Configuration configuration,
Span<Vector4> sourceVectors, Span<Vector4> sourceVectors,
Span<TPixel> destPixels) Span<TPixel> destinationPixels)
=> this.FromVector4Destructive(configuration, sourceVectors, destPixels, PixelConversionModifiers.None); => this.FromVector4Destructive(configuration, sourceVectors, destinationPixels, PixelConversionModifiers.None);
/// <summary> /// <summary>
/// Bulk version of <see cref="IPixel.ToVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVectors'. /// Bulk version of <see cref="IPixel.ToVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVectors'.
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param> /// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="Span{T}"/> to the destination vectors.</param> /// <param name="destinationVectors">The <see cref="Span{T}"/> to the destination vectors.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param> /// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param>
public virtual void ToVector4( public virtual void ToVector4(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TPixel> sourcePixels, ReadOnlySpan<TPixel> sourcePixels,
Span<Vector4> destVectors, Span<Vector4> destinationVectors,
PixelConversionModifiers modifiers) PixelConversionModifiers modifiers)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Utils.Vector4Converters.Default.ToVector4(sourcePixels, destVectors, modifiers); Utils.Vector4Converters.Default.ToVector4(sourcePixels, destinationVectors, modifiers);
} }
/// <summary> /// <summary>
@ -85,14 +85,22 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param> /// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="Span{T}"/> to the destination vectors.</param> /// <param name="destinationVectors">The <see cref="Span{T}"/> to the destination vectors.</param>
public void ToVector4( public void ToVector4(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TPixel> sourcePixels, ReadOnlySpan<TPixel> sourcePixels,
Span<Vector4> destVectors) Span<Vector4> destinationVectors)
=> this.ToVector4(configuration, sourcePixels, destVectors, PixelConversionModifiers.None); => this.ToVector4(configuration, sourcePixels, destinationVectors, PixelConversionModifiers.None);
internal virtual void From<TSourcePixel>( /// <summary>
/// Bulk operation that copies the <paramref name="sourcePixels"/> to <paramref name="destinationPixels"/> in
/// <typeparamref name="TSourcePixel"/> format.
/// </summary>
/// <typeparam name="TSourcePixel">The destination pixel type.</typeparam>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourcePixels">The <see cref="ReadOnlySpan{TSourcePixel}"/> to the source pixels.</param>
/// <param name="destinationPixels">The <see cref="Span{TPixel}"/> to the destination pixels.</param>
public virtual void From<TSourcePixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels, ReadOnlySpan<TSourcePixel> sourcePixels,
Span<TPixel> destinationPixels) Span<TPixel> destinationPixels)
@ -126,13 +134,14 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <summary> /// <summary>
/// Converts 'sourcePixels.Length' pixels from 'sourcePixels' into 'destinationPixels'. /// Bulk operation that copies the <paramref name="sourcePixels"/> to <paramref name="destinationPixels"/> in
/// <typeparamref name="TDestinationPixel"/> format.
/// </summary> /// </summary>
/// <typeparam name="TDestinationPixel">The destination pixel type.</typeparam> /// <typeparam name="TDestinationPixel">The destination pixel type.</typeparam>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param> /// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param> /// <param name="sourcePixels">The <see cref="ReadOnlySpan{TPixel}"/> to the source pixels.</param>
/// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param> /// <param name="destinationPixels">The <see cref="Span{TDestinationPixel}"/> to the destination pixels.</param>
internal virtual void To<TDestinationPixel>( public virtual void To<TDestinationPixel>(
Configuration configuration, Configuration configuration,
ReadOnlySpan<TPixel> sourcePixels, ReadOnlySpan<TPixel> sourcePixels,
Span<TDestinationPixel> destinationPixels) Span<TDestinationPixel> destinationPixels)

10
src/ImageSharp/Primitives/ColorMatrix.cs

@ -204,7 +204,7 @@ namespace SixLabors.ImageSharp
/// <returns>The resulting matrix.</returns> /// <returns>The resulting matrix.</returns>
public static ColorMatrix operator +(ColorMatrix value1, ColorMatrix value2) public static ColorMatrix operator +(ColorMatrix value1, ColorMatrix value2)
{ {
ColorMatrix m; var m = default(ColorMatrix);
m.M11 = value1.M11 + value2.M11; m.M11 = value1.M11 + value2.M11;
m.M12 = value1.M12 + value2.M12; m.M12 = value1.M12 + value2.M12;
@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp
/// <returns>The result of the subtraction.</returns> /// <returns>The result of the subtraction.</returns>
public static ColorMatrix operator -(ColorMatrix value1, ColorMatrix value2) public static ColorMatrix operator -(ColorMatrix value1, ColorMatrix value2)
{ {
ColorMatrix m; var m = default(ColorMatrix);
m.M11 = value1.M11 - value2.M11; m.M11 = value1.M11 - value2.M11;
m.M12 = value1.M12 - value2.M12; m.M12 = value1.M12 - value2.M12;
@ -271,7 +271,7 @@ namespace SixLabors.ImageSharp
/// <returns>The negated matrix.</returns> /// <returns>The negated matrix.</returns>
public static ColorMatrix operator -(ColorMatrix value) public static ColorMatrix operator -(ColorMatrix value)
{ {
ColorMatrix m; var m = default(ColorMatrix);
m.M11 = -value.M11; m.M11 = -value.M11;
m.M12 = -value.M12; m.M12 = -value.M12;
@ -305,7 +305,7 @@ namespace SixLabors.ImageSharp
/// <returns>The result of the multiplication.</returns> /// <returns>The result of the multiplication.</returns>
public static ColorMatrix operator *(ColorMatrix value1, ColorMatrix value2) public static ColorMatrix operator *(ColorMatrix value1, ColorMatrix value2)
{ {
ColorMatrix m; var m = default(ColorMatrix);
// First row // First row
m.M11 = (value1.M11 * value2.M11) + (value1.M12 * value2.M21) + (value1.M13 * value2.M31) + (value1.M14 * value2.M41); m.M11 = (value1.M11 * value2.M11) + (value1.M12 * value2.M21) + (value1.M13 * value2.M31) + (value1.M14 * value2.M41);
@ -348,7 +348,7 @@ namespace SixLabors.ImageSharp
/// <returns>The scaled matrix.</returns> /// <returns>The scaled matrix.</returns>
public static ColorMatrix operator *(ColorMatrix value1, float value2) public static ColorMatrix operator *(ColorMatrix value1, float value2)
{ {
ColorMatrix m; var m = default(ColorMatrix);
m.M11 = value1.M11 * value2; m.M11 = value1.M11 * value2;
m.M12 = value1.M12 * value2; m.M12 = value1.M12 * value2;

102
src/ImageSharp/Processing/Extensions/Effects/PixelRowDelegateExtensions.cs

@ -0,0 +1,102 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Effects;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Defines extension methods that allow the application of user defined processing delegate to an <see cref="Image"/>.
/// </summary>
public static class PixelRowDelegateExtensions
{
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation)
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers));
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle)
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation)
=> ProcessPixelRowsAsVector4(source, rowOperation, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers));
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle)
=> ProcessPixelRowsAsVector4(source, rowOperation, rectangle, PixelConversionModifiers.None);
/// <summary>
/// Applies a user defined processing delegate to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="rowOperation">The user defined processing delegate to use to modify image rows.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ProcessPixelRowsAsVector4(this IImageProcessingContext source, PixelRowOperation<Point> rowOperation, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelRowDelegateProcessor(rowOperation, modifiers), rectangle);
}
}

102
src/ImageSharp/Processing/Extensions/Effects/PixelShaderExtensions.cs

@ -1,102 +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.Effects;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Defines extension methods that allow the application of user defined pixel shaders to an <see cref="Image"/>.
/// </summary>
public static class PixelShaderExtensions
{
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader, modifiers));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, Rectangle rectangle)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PixelShader pixelShader, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PixelShaderProcessor(pixelShader, modifiers), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader, modifiers));
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, Rectangle rectangle)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader), rectangle);
/// <summary>
/// Applies a user defined pixel shader to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="pixelShader">The user defined pixel shader to use to modify images.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyPixelShaderProcessor(this IImageProcessingContext source, PositionAwarePixelShader pixelShader, Rectangle rectangle, PixelConversionModifiers modifiers)
=> source.ApplyProcessor(new PositionAwarePixelShaderProcessor(pixelShader, modifiers), rectangle);
}
}

27
src/ImageSharp/Processing/PixelRowOperation.cs

@ -0,0 +1,27 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// A <see langword="delegate"/> representing a user defined processing delegate to use to modify image rows.
/// </summary>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
public delegate void PixelRowOperation(Span<Vector4> span);
/// <summary>
/// A <see langword="delegate"/> representing a user defined processing delegate to use to modify image rows.
/// </summary>
/// <typeparam name="T">
/// The type of the parameter of the method that this delegate encapsulates.
/// This type parameter is contravariant.That is, you can use either the type you specified or any type that is less derived.
/// </typeparam>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <param name="value">The parameter of the method that this delegate encapsulates.</param>
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
public delegate void PixelRowOperation<in T>(Span<Vector4> span, T value);
}

15
src/ImageSharp/Processing/PixelShader.cs

@ -1,15 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// A <see langword="delegate"/> representing a user defined pixel shader.
/// </summary>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
public delegate void PixelShader(Span<Vector4> span);
}

16
src/ImageSharp/Processing/PositionAwarePixelShader.cs

@ -1,16 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// A <see langword="delegate"/> representing a user defined pixel shader.
/// </summary>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <param name="offset">The initial horizontal and vertical offset for the input pixels to process.</param>
/// <remarks>The <see cref="Vector4.X"/>, <see cref="Vector4.Y"/>, <see cref="Vector4.Z"/>, and <see cref="Vector4.W"/> fields map the RGBA channels respectively.</remarks>
public delegate void PositionAwarePixelShader(Span<Vector4> span, Point offset);
}

147
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -2,7 +2,9 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Buffers;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Advanced.ParallelUtils;
@ -52,82 +54,113 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
int radius = brushSize >> 1; int radius = brushSize >> 1;
int levels = this.definition.Levels; int levels = this.definition.Levels;
int rowWidth = source.Width;
int rectangleWidth = this.SourceRectangle.Width;
Configuration configuration = this.Configuration;
using Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size());
source.CopyTo(targetPixels);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY);
ParallelHelper.IterateRows(
workingRect,
this.Configuration,
(rows) =>
{
/* Allocate the two temporary Vector4 buffers, one for the source row and one for the target row.
* The ParallelHelper.IterateRowsWithTempBuffers overload is not used in this case because
* the two allocated buffers have a length equal to the width of the source image,
* and not just equal to the width of the target rectangle to process.
* Furthermore, there are two buffers being allocated in this case, so using that overload would
* have still required the explicit allocation of the secondary buffer.
* Similarly, one temporary float buffer is also allocated from the pool, and that is used
* to create the target bins for all the color channels being processed.
* This buffer is only rented once outside of the main processing loop, and its contents
* are cleared for each loop iteration, to avoid the repeated allocation for each processed pixel. */
using (IMemoryOwner<Vector4> sourceRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(rowWidth))
using (IMemoryOwner<Vector4> targetRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(rowWidth))
using (IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4))
{
Span<Vector4> sourceRowVector4Span = sourceRowBuffer.Memory.Span;
Span<Vector4> sourceRowAreaVector4Span = sourceRowVector4Span.Slice(startX, rectangleWidth);
Span<Vector4> targetRowVector4Span = targetRowBuffer.Memory.Span;
Span<Vector4> targetRowAreaVector4Span = targetRowVector4Span.Slice(startX, rectangleWidth);
ref float binsRef = ref bins.GetReference();
ref int intensityBinRef = ref Unsafe.As<float, int>(ref binsRef);
ref float redBinRef = ref Unsafe.Add(ref binsRef, levels);
ref float blueBinRef = ref Unsafe.Add(ref redBinRef, levels);
ref float greenBinRef = ref Unsafe.Add(ref blueBinRef, levels);
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> sourceRowPixelSpan = source.GetPixelRowSpan(y);
Span<TPixel> sourceRowAreaPixelSpan = sourceRowPixelSpan.Slice(startX, rectangleWidth);
using (Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size())) PixelOperations<TPixel>.Instance.ToVector4(configuration, sourceRowAreaPixelSpan, sourceRowAreaVector4Span);
{
source.CopyTo(targetPixels);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); for (int x = startX; x < endX; x++)
ParallelHelper.IterateRows(
workingRect,
this.Configuration,
rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<TPixel> sourceRow = source.GetPixelRowSpan(y); int maxIntensity = 0;
Span<TPixel> targetRow = targetPixels.GetRowSpan(y); int maxIndex = 0;
for (int x = startX; x < endX; x++)
{
int maxIntensity = 0;
int maxIndex = 0;
var intensityBin = new int[levels]; // Clear the current shared buffer before processing each target pixel
var redBin = new float[levels]; bins.Memory.Span.Clear();
var blueBin = new float[levels];
var greenBin = new float[levels];
for (int fy = 0; fy <= radius; fy++) for (int fy = 0; fy <= radius; fy++)
{ {
int fyr = fy - radius; int fyr = fy - radius;
int offsetY = y + fyr; int offsetY = y + fyr;
offsetY = offsetY.Clamp(0, maxY); offsetY = offsetY.Clamp(0, maxY);
Span<TPixel> sourceOffsetRow = source.GetPixelRowSpan(offsetY); Span<TPixel> sourceOffsetRow = source.GetPixelRowSpan(offsetY);
for (int fx = 0; fx <= radius; fx++) for (int fx = 0; fx <= radius; fx++)
{ {
int fxr = fx - radius; int fxr = fx - radius;
int offsetX = x + fxr; int offsetX = x + fxr;
offsetX = offsetX.Clamp(0, maxX); offsetX = offsetX.Clamp(0, maxX);
var vector = sourceOffsetRow[offsetX].ToVector4(); var vector = sourceOffsetRow[offsetX].ToVector4();
float sourceRed = vector.X; float sourceRed = vector.X;
float sourceBlue = vector.Z; float sourceBlue = vector.Z;
float sourceGreen = vector.Y; float sourceGreen = vector.Y;
int currentIntensity = (int)MathF.Round( int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1));
(sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1));
intensityBin[currentIntensity]++; Unsafe.Add(ref intensityBinRef, currentIntensity)++;
blueBin[currentIntensity] += sourceBlue; Unsafe.Add(ref redBinRef, currentIntensity) += sourceRed;
greenBin[currentIntensity] += sourceGreen; Unsafe.Add(ref blueBinRef, currentIntensity) += sourceBlue;
redBin[currentIntensity] += sourceRed; Unsafe.Add(ref greenBinRef, currentIntensity) += sourceGreen;
if (intensityBin[currentIntensity] > maxIntensity) if (Unsafe.Add(ref intensityBinRef, currentIntensity) > maxIntensity)
{ {
maxIntensity = intensityBin[currentIntensity]; maxIntensity = Unsafe.Add(ref intensityBinRef, currentIntensity);
maxIndex = currentIntensity; maxIndex = currentIntensity;
}
} }
}
float red = MathF.Abs(redBin[maxIndex] / maxIntensity); float red = MathF.Abs(Unsafe.Add(ref redBinRef, maxIndex) / maxIntensity);
float green = MathF.Abs(greenBin[maxIndex] / maxIntensity); float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, maxIndex) / maxIntensity);
float blue = MathF.Abs(blueBin[maxIndex] / maxIntensity); float green = MathF.Abs(Unsafe.Add(ref greenBinRef, maxIndex) / maxIntensity);
float alpha = sourceRowVector4Span[x].W;
ref TPixel pixel = ref targetRow[x]; targetRowVector4Span[x] = new Vector4(red, green, blue, alpha);
pixel.FromVector4(
new Vector4(red, green, blue, sourceRow[x].ToVector4().W));
}
} }
} }
});
Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels); Span<TPixel> targetRowAreaPixelSpan = targetPixels.GetRowSpan(y).Slice(startX, rectangleWidth);
}
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, targetRowAreaVector4Span, targetRowAreaPixelSpan);
}
}
});
Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels);
} }
} }
} }

39
src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined row processing delegate to the image.
/// </summary>
internal sealed class PixelRowDelegateProcessor : IImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelRowDelegateProcessor"/> class.
/// </summary>
/// <param name="pixelRowOperation">The user defined, row processing delegate.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PixelRowDelegateProcessor(PixelRowOperation pixelRowOperation, PixelConversionModifiers modifiers)
{
this.PixelRowOperation = pixelRowOperation;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined row processing delegate to the image.
/// </summary>
public PixelRowOperation PixelRowOperation { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PixelRowDelegateProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

21
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessorBase.cs → src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessorBase{TPixel}.cs

@ -3,7 +3,6 @@
using System; using System;
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Advanced.ParallelUtils;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -11,10 +10,10 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects namespace SixLabors.ImageSharp.Processing.Processors.Effects
{ {
/// <summary> /// <summary>
/// Applies a user defined pixel shader effect through a given delegate. /// The base class for all processors that accept a user defined row processing delegate.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class PixelShaderProcessorBase<TPixel> : ImageProcessor<TPixel> internal abstract class PixelRowDelegateProcessorBase<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
@ -23,17 +22,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
private readonly PixelConversionModifiers modifiers; private readonly PixelConversionModifiers modifiers;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessorBase{TPixel}"/> class. /// Initializes a new instance of the <see cref="PixelRowDelegateProcessorBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param> /// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
protected PixelShaderProcessorBase(Configuration configuration, PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle) protected PixelRowDelegateProcessorBase(Configuration configuration, PixelConversionModifiers modifiers, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle) : base(configuration, source, sourceRectangle)
{ => this.modifiers = modifiers;
this.modifiers = modifiers;
}
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source) protected override void OnFrameApply(ImageFrame<TPixel> source)
@ -55,8 +52,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
Span<TPixel> rowSpan = source.GetPixelRowSpan(y).Slice(startX, length); Span<TPixel> rowSpan = source.GetPixelRowSpan(y).Slice(startX, length);
PixelOperations<TPixel>.Instance.ToVector4(configuration, rowSpan, vectorSpan, modifiers); PixelOperations<TPixel>.Instance.ToVector4(configuration, rowSpan, vectorSpan, modifiers);
// Run the user defined pixel shader on the current row of pixels // Run the user defined pixel shader to the current row of pixels
this.ApplyPixelShader(vectorSpan, new Point(startX, y)); this.ApplyPixelRowDelegate(vectorSpan, new Point(startX, y));
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, rowSpan, modifiers); PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, rowSpan, modifiers);
} }
@ -64,10 +61,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
} }
/// <summary> /// <summary>
/// Applies the current pixel shader effect on a target row of preprocessed pixels. /// Applies the current pixel row delegate to a target row of preprocessed pixels.
/// </summary> /// </summary>
/// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param> /// <param name="span">The target row of <see cref="Vector4"/> pixels to process.</param>
/// <param name="offset">The initial horizontal and vertical offset for the input pixels to process.</param> /// <param name="offset">The initial horizontal and vertical offset for the input pixels to process.</param>
protected abstract void ApplyPixelShader(Span<Vector4> span, Point offset); protected abstract void ApplyPixelRowDelegate(Span<Vector4> span, Point offset);
} }
} }

18
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor{TPixel}.cs → src/ImageSharp/Processing/Processors/Effects/PixelRowDelegateProcessor{TPixel}.cs

@ -9,31 +9,31 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects namespace SixLabors.ImageSharp.Processing.Processors.Effects
{ {
/// <summary> /// <summary>
/// Applies a user defined pixel shader effect through a given delegate. /// Applies a user defined row processing delegate to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PixelShaderProcessor<TPixel> : PixelShaderProcessorBase<TPixel> internal sealed class PixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The user defined pixel shader. /// The user defined pixel row processing delegate.
/// </summary> /// </summary>
private readonly PixelShader pixelShader; private readonly PixelRowOperation pixelRowOperation;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PixelRowDelegateProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PixelShaderProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="PixelRowDelegateProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PixelShaderProcessor(Configuration configuration, PixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PixelRowDelegateProcessor(Configuration configuration, PixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, definition.Modifiers, source, sourceRectangle) : base(configuration, definition.Modifiers, source, sourceRectangle)
{ {
this.pixelShader = definition.PixelShader; this.pixelRowOperation = definition.PixelRowOperation;
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void ApplyPixelShader(Span<Vector4> span, Point offset) => this.pixelShader(span); protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span);
} }
} }

58
src/ImageSharp/Processing/Processors/Effects/PixelShaderProcessor.cs

@ -1,58 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// </summary>
public sealed class PixelShaderProcessor : IImageProcessor
{
/// <summary>
/// The default <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public const PixelConversionModifiers DefaultModifiers = PixelConversionModifiers.None;
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
public PixelShaderProcessor(PixelShader pixelShader)
{
this.PixelShader = pixelShader;
this.Modifiers = DefaultModifiers;
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PixelShaderProcessor(PixelShader pixelShader, PixelConversionModifiers modifiers)
{
this.PixelShader = pixelShader;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined pixel shader.
/// </summary>
public PixelShader PixelShader { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

39
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor.cs

@ -0,0 +1,39 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined, position aware, row processing delegate to the image.
/// </summary>
internal sealed class PositionAwarePixelRowDelegateProcessor : IImageProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor"/> class.
/// </summary>
/// <param name="pixelRowOperation">The user defined, position aware, row processing delegate.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PositionAwarePixelRowDelegateProcessor(PixelRowOperation<Point> pixelRowOperation, PixelConversionModifiers modifiers)
{
this.PixelRowOperation = pixelRowOperation;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined, position aware, row processing delegate.
/// </summary>
public PixelRowOperation<Point> PixelRowOperation { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PositionAwarePixelRowDelegateProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

19
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor{TPixel}.cs → src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelRowDelegateProcessor{TPixel}.cs

@ -9,31 +9,28 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects namespace SixLabors.ImageSharp.Processing.Processors.Effects
{ {
/// <summary> /// <summary>
/// Applies a user defined pixel shader effect through a given delegate. /// Applies a user defined, position aware, row processing delegate to the image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PositionAwarePixelShaderProcessor<TPixel> : PixelShaderProcessorBase<TPixel> internal sealed class PositionAwarePixelRowDelegateProcessor<TPixel> : PixelRowDelegateProcessorBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> private readonly PixelRowOperation<Point> pixelRowOperation;
/// The user defined pixel shader.
/// </summary>
private readonly PositionAwarePixelShader pixelShader;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor{TPixel}"/> class. /// Initializes a new instance of the <see cref="PositionAwarePixelRowDelegateProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="definition">The <see cref="PositionAwarePixelShaderProcessor"/> defining the processor parameters.</param> /// <param name="definition">The <see cref="PositionAwarePixelRowDelegateProcessor"/> defining the processor parameters.</param>
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param> /// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param> /// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public PositionAwarePixelShaderProcessor(Configuration configuration, PositionAwarePixelShaderProcessor definition, Image<TPixel> source, Rectangle sourceRectangle) public PositionAwarePixelRowDelegateProcessor(Configuration configuration, PositionAwarePixelRowDelegateProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, definition.Modifiers, source, sourceRectangle) : base(configuration, definition.Modifiers, source, sourceRectangle)
{ {
this.pixelShader = definition.PixelShader; this.pixelRowOperation = definition.PixelRowOperation;
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void ApplyPixelShader(Span<Vector4> span, Point offset) => this.pixelShader(span, offset); protected override void ApplyPixelRowDelegate(Span<Vector4> span, Point offset) => this.pixelRowOperation(span, offset);
} }
} }

58
src/ImageSharp/Processing/Processors/Effects/PositionAwarePixelShaderProcessor.cs

@ -1,58 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Effects
{
/// <summary>
/// Applies a user defined pixel shader effect through a given delegate.
/// </summary>
public sealed class PositionAwarePixelShaderProcessor : IImageProcessor
{
/// <summary>
/// The default <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public const PixelConversionModifiers DefaultModifiers = PixelConversionModifiers.None;
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
public PositionAwarePixelShaderProcessor(PositionAwarePixelShader pixelShader)
{
this.PixelShader = pixelShader;
this.Modifiers = DefaultModifiers;
}
/// <summary>
/// Initializes a new instance of the <see cref="PositionAwarePixelShaderProcessor"/> class.
/// </summary>
/// <param name="pixelShader">
/// The user defined pixel shader to use to modify images.
/// </param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.</param>
public PositionAwarePixelShaderProcessor(PositionAwarePixelShader pixelShader, PixelConversionModifiers modifiers)
{
this.PixelShader = pixelShader;
this.Modifiers = modifiers;
}
/// <summary>
/// Gets the user defined pixel shader.
/// </summary>
public PositionAwarePixelShader PixelShader { get; }
/// <summary>
/// Gets the <see cref="PixelConversionModifiers"/> to apply during the pixel conversions.
/// </summary>
public PixelConversionModifiers Modifiers { get; }
/// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
where TPixel : struct, IPixel<TPixel>
=> new PositionAwarePixelShaderProcessor<TPixel>(configuration, this, source, sourceRectangle);
}
}

10
src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs

@ -64,9 +64,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
int width = maxX - minX; int width = maxX - minX;
var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY); var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
Configuration configuration = this.Configuration;
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
using (IMemoryOwner<TPixel> colors = source.MemoryAllocator.Allocate<TPixel>(width)) using (IMemoryOwner<TPixel> colors = memoryAllocator.Allocate<TPixel>(width))
using (IMemoryOwner<float> amount = source.MemoryAllocator.Allocate<float>(width)) using (IMemoryOwner<float> amount = memoryAllocator.Allocate<float>(width))
{ {
// Be careful! Do not capture colorSpan & amountSpan in the lambda below! // Be careful! Do not capture colorSpan & amountSpan in the lambda below!
Span<TPixel> colorSpan = colors.GetSpan(); Span<TPixel> colorSpan = colors.GetSpan();
@ -79,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
ParallelHelper.IterateRows( ParallelHelper.IterateRows(
workingRect, workingRect,
this.Configuration, configuration,
rows => rows =>
{ {
for (int y = rows.Min; y < rows.Max; y++) for (int y = rows.Min; y < rows.Max; y++)
@ -89,7 +91,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
// This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one // This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one
blender.Blend( blender.Blend(
source.Configuration, configuration,
destination, destination,
colors.GetSpan(), colors.GetSpan(),
destination, destination,

8
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor{TPixel}.cs

@ -76,14 +76,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY); var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
float blendPercentage = this.definition.GraphicsOptions.BlendPercentage; float blendPercentage = this.definition.GraphicsOptions.BlendPercentage;
Configuration configuration = this.Configuration;
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
using (IMemoryOwner<TPixel> rowColors = source.MemoryAllocator.Allocate<TPixel>(width)) using (IMemoryOwner<TPixel> rowColors = memoryAllocator.Allocate<TPixel>(width))
{ {
rowColors.GetSpan().Fill(glowColor); rowColors.GetSpan().Fill(glowColor);
ParallelHelper.IterateRowsWithTempBuffer<float>( ParallelHelper.IterateRowsWithTempBuffer<float>(
workingRect, workingRect,
this.Configuration, configuration,
(rows, amounts) => (rows, amounts) =>
{ {
Span<float> amountsSpan = amounts.Span; Span<float> amountsSpan = amounts.Span;
@ -102,7 +104,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width);
this.blender.Blend( this.blender.Blend(
source.Configuration, configuration,
destination, destination,
destination, destination,
rowColors.GetSpan(), rowColors.GetSpan(),

8
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs

@ -80,14 +80,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY); var workingRect = Rectangle.FromLTRB(minX, minY, maxX, maxY);
float blendPercentage = this.definition.GraphicsOptions.BlendPercentage; float blendPercentage = this.definition.GraphicsOptions.BlendPercentage;
Configuration configuration = this.Configuration;
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
using (IMemoryOwner<TPixel> rowColors = source.MemoryAllocator.Allocate<TPixel>(width)) using (IMemoryOwner<TPixel> rowColors = memoryAllocator.Allocate<TPixel>(width))
{ {
rowColors.GetSpan().Fill(vignetteColor); rowColors.GetSpan().Fill(vignetteColor);
ParallelHelper.IterateRowsWithTempBuffer<float>( ParallelHelper.IterateRowsWithTempBuffer<float>(
workingRect, workingRect,
this.Configuration, configuration,
(rows, amounts) => (rows, amounts) =>
{ {
Span<float> amountsSpan = amounts.Span; Span<float> amountsSpan = amounts.Span;
@ -105,7 +107,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width);
this.blender.Blend( this.blender.Blend(
source.Configuration, configuration,
destination, destination,
destination, destination,
rowColors.GetSpan(), rowColors.GetSpan(),

22
src/ImageSharp/Processing/Processors/Quantization/FrameQuantizer{TPixel}.cs

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Dithering;
@ -39,6 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="FrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The quantizer</param> /// <param name="quantizer">The quantizer</param>
/// <param name="singlePass"> /// <param name="singlePass">
/// If true, the quantization process only needs to loop through the source pixels once /// If true, the quantization process only needs to loop through the source pixels once
@ -48,10 +50,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// only call the <see cref="SecondPass(ImageFrame{TPixel}, Span{byte}, ReadOnlySpan{TPixel}, int, int)"/> method. /// only call the <see cref="SecondPass(ImageFrame{TPixel}, Span{byte}, ReadOnlySpan{TPixel}, int, int)"/> method.
/// If two passes are required, the code will also call <see cref="FirstPass(ImageFrame{TPixel}, int, int)"/>. /// If two passes are required, the code will also call <see cref="FirstPass(ImageFrame{TPixel}, int, int)"/>.
/// </remarks> /// </remarks>
protected FrameQuantizer(IQuantizer quantizer, bool singlePass) protected FrameQuantizer(Configuration configuration, IQuantizer quantizer, bool singlePass)
{ {
Guard.NotNull(quantizer, nameof(quantizer)); Guard.NotNull(quantizer, nameof(quantizer));
this.Configuration = configuration;
this.Diffuser = quantizer.Diffuser; this.Diffuser = quantizer.Diffuser;
this.Dither = this.Diffuser != null; this.Dither = this.Diffuser != null;
this.singlePass = singlePass; this.singlePass = singlePass;
@ -60,6 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="FrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="diffuser">The diffuser</param> /// <param name="diffuser">The diffuser</param>
/// <param name="singlePass"> /// <param name="singlePass">
/// If true, the quantization process only needs to loop through the source pixels once /// If true, the quantization process only needs to loop through the source pixels once
@ -69,8 +73,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// only call the <see cref="SecondPass(ImageFrame{TPixel}, Span{byte}, ReadOnlySpan{TPixel}, int, int)"/> method. /// only call the <see cref="SecondPass(ImageFrame{TPixel}, Span{byte}, ReadOnlySpan{TPixel}, int, int)"/> method.
/// If two passes are required, the code will also call <see cref="FirstPass(ImageFrame{TPixel}, int, int)"/>. /// If two passes are required, the code will also call <see cref="FirstPass(ImageFrame{TPixel}, int, int)"/>.
/// </remarks> /// </remarks>
protected FrameQuantizer(IErrorDiffuser diffuser, bool singlePass) protected FrameQuantizer(Configuration configuration, IErrorDiffuser diffuser, bool singlePass)
{ {
this.Configuration = configuration;
this.Diffuser = diffuser; this.Diffuser = diffuser;
this.Dither = this.Diffuser != null; this.Dither = this.Diffuser != null;
this.singlePass = singlePass; this.singlePass = singlePass;
@ -82,6 +87,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <inheritdoc /> /// <inheritdoc />
public bool Dither { get; } public bool Dither { get; }
/// <summary>
/// Gets the configuration which allows altering default behaviour or extending the library.
/// </summary>
protected Configuration Configuration { get; }
/// <inheritdoc/> /// <inheritdoc/>
public void Dispose() public void Dispose()
{ {
@ -108,14 +118,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
// Collect the palette. Required before the second pass runs. // Collect the palette. Required before the second pass runs.
ReadOnlyMemory<TPixel> palette = this.GetPalette(); ReadOnlyMemory<TPixel> palette = this.GetPalette();
this.paletteVector = image.Configuration.MemoryAllocator.Allocate<Vector4>(palette.Length); MemoryAllocator memoryAllocator = this.Configuration.MemoryAllocator;
this.paletteVector = memoryAllocator.Allocate<Vector4>(palette.Length);
PixelOperations<TPixel>.Instance.ToVector4( PixelOperations<TPixel>.Instance.ToVector4(
image.Configuration, this.Configuration,
palette.Span, palette.Span,
this.paletteVector.Memory.Span, this.paletteVector.Memory.Span,
PixelConversionModifiers.Scale); PixelConversionModifiers.Scale);
var quantizedFrame = new QuantizedFrame<TPixel>(image.MemoryAllocator, width, height, palette); var quantizedFrame = new QuantizedFrame<TPixel>(memoryAllocator, width, height, palette);
Span<byte> pixelSpan = quantizedFrame.GetWritablePixelSpan(); Span<byte> pixelSpan = quantizedFrame.GetWritablePixelSpan();
if (this.Dither) if (this.Dither)

10
src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs

@ -37,27 +37,29 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OctreeFrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="OctreeFrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The octree quantizer</param> /// <param name="quantizer">The octree quantizer</param>
/// <remarks> /// <remarks>
/// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree, /// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree,
/// the second pass quantizes a color based on the nodes in the tree /// the second pass quantizes a color based on the nodes in the tree
/// </remarks> /// </remarks>
public OctreeFrameQuantizer(OctreeQuantizer quantizer) public OctreeFrameQuantizer(Configuration configuration, OctreeQuantizer quantizer)
: this(quantizer, quantizer.MaxColors) : this(configuration, quantizer, quantizer.MaxColors)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OctreeFrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="OctreeFrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The octree quantizer.</param> /// <param name="quantizer">The octree quantizer.</param>
/// <param name="maxColors">The maximum number of colors to hold in the color palette.</param> /// <param name="maxColors">The maximum number of colors to hold in the color palette.</param>
/// <remarks> /// <remarks>
/// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree, /// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree,
/// the second pass quantizes a color based on the nodes in the tree /// the second pass quantizes a color based on the nodes in the tree
/// </remarks> /// </remarks>
public OctreeFrameQuantizer(OctreeQuantizer quantizer, int maxColors) public OctreeFrameQuantizer(Configuration configuration, OctreeQuantizer quantizer, int maxColors)
: base(quantizer, false) : base(configuration, quantizer, false)
{ {
this.colors = maxColors; this.colors = maxColors;
this.octree = new Octree(ImageMaths.GetBitsNeededForColorDepth(this.colors).Clamp(1, 8)); this.octree = new Octree(ImageMaths.GetBitsNeededForColorDepth(this.colors).Clamp(1, 8));

8
src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -83,16 +83,16 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <inheritdoc /> /// <inheritdoc />
public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration) public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
=> new OctreeFrameQuantizer<TPixel>(this); => new OctreeFrameQuantizer<TPixel>(configuration, this);
/// <inheritdoc/> /// <inheritdoc/>
public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration, int maxColors) public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration, int maxColors)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
maxColors = maxColors.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors); maxColors = maxColors.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors);
return new OctreeFrameQuantizer<TPixel>(this, maxColors); return new OctreeFrameQuantizer<TPixel>(configuration, this, maxColors);
} }
private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null;
} }
} }

5
src/ImageSharp/Processing/Processors/Quantization/PaletteFrameQuantizer{TPixel}.cs

@ -26,10 +26,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PaletteFrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="PaletteFrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="diffuser">The palette quantizer.</param> /// <param name="diffuser">The palette quantizer.</param>
/// <param name="colors">An array of all colors in the palette.</param> /// <param name="colors">An array of all colors in the palette.</param>
public PaletteFrameQuantizer(IErrorDiffuser diffuser, ReadOnlyMemory<TPixel> colors) public PaletteFrameQuantizer(Configuration configuration, IErrorDiffuser diffuser, ReadOnlyMemory<TPixel> colors)
: base(diffuser, true) => this.palette = colors; : base(configuration, diffuser, true) => this.palette = colors;
/// <inheritdoc/> /// <inheritdoc/>
protected override void SecondPass( protected override void SecondPass(

4
src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs

@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
{ {
var palette = new TPixel[this.Palette.Length]; var palette = new TPixel[this.Palette.Length];
Color.ToPixel(configuration, this.Palette.Span, palette.AsSpan()); Color.ToPixel(configuration, this.Palette.Span, palette.AsSpan());
return new PaletteFrameQuantizer<TPixel>(this.Diffuser, palette); return new PaletteFrameQuantizer<TPixel>(configuration, this.Diffuser, palette);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
var palette = new TPixel[max]; var palette = new TPixel[max];
Color.ToPixel(configuration, this.Palette.Span.Slice(0, max), palette.AsSpan()); Color.ToPixel(configuration, this.Palette.Span.Slice(0, max), palette.AsSpan());
return new PaletteFrameQuantizer<TPixel>(this.Diffuser, palette); return new PaletteFrameQuantizer<TPixel>(configuration, this.Diffuser, palette);
} }
private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null;

42
src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs

@ -37,6 +37,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
internal sealed class WuFrameQuantizer<TPixel> : FrameQuantizer<TPixel> internal sealed class WuFrameQuantizer<TPixel> : FrameQuantizer<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private readonly MemoryAllocator memoryAllocator;
// The following two variables determine the amount of bits to preserve when calculating the histogram. // The following two variables determine the amount of bits to preserve when calculating the histogram.
// Reducing the value of these numbers the granularity of the color maps produced, making it much faster // Reducing the value of these numbers the granularity of the color maps produced, making it much faster
// and using much less memory but potentially less accurate. Current results are very good though! // and using much less memory but potentially less accurate. Current results are very good though!
@ -121,39 +123,39 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WuFrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="WuFrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/>.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The wu quantizer</param> /// <param name="quantizer">The Wu quantizer</param>
/// <remarks> /// <remarks>
/// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram, /// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram,
/// the second pass quantizes a color based on the position in the histogram. /// the second pass quantizes a color based on the position in the histogram.
/// </remarks> /// </remarks>
public WuFrameQuantizer(MemoryAllocator memoryAllocator, WuQuantizer quantizer) public WuFrameQuantizer(Configuration configuration, WuQuantizer quantizer)
: this(memoryAllocator, quantizer, quantizer.MaxColors) : this(configuration, quantizer, quantizer.MaxColors)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WuFrameQuantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="WuFrameQuantizer{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/>.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
/// <param name="quantizer">The wu quantizer.</param> /// <param name="quantizer">The Wu quantizer.</param>
/// <param name="maxColors">The maximum number of colors to hold in the color palette.</param> /// <param name="maxColors">The maximum number of colors to hold in the color palette.</param>
/// <remarks> /// <remarks>
/// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram, /// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram,
/// the second pass quantizes a color based on the position in the histogram. /// the second pass quantizes a color based on the position in the histogram.
/// </remarks> /// </remarks>
public WuFrameQuantizer(MemoryAllocator memoryAllocator, WuQuantizer quantizer, int maxColors) public WuFrameQuantizer(Configuration configuration, WuQuantizer quantizer, int maxColors)
: base(quantizer, false) : base(configuration, quantizer, false)
{ {
Guard.NotNull(memoryAllocator, nameof(memoryAllocator)); this.memoryAllocator = this.Configuration.MemoryAllocator;
this.vwt = memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean); this.vwt = this.memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean);
this.vmr = memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean); this.vmr = this.memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean);
this.vmg = memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean); this.vmg = this.memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean);
this.vmb = memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean); this.vmb = this.memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean);
this.vma = memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean); this.vma = this.memoryAllocator.Allocate<long>(TableLength, AllocationOptions.Clean);
this.m2 = memoryAllocator.Allocate<double>(TableLength, AllocationOptions.Clean); this.m2 = this.memoryAllocator.Allocate<double>(TableLength, AllocationOptions.Clean);
this.tag = memoryAllocator.Allocate<byte>(TableLength, AllocationOptions.Clean); this.tag = this.memoryAllocator.Allocate<byte>(TableLength, AllocationOptions.Clean);
this.colors = maxColors; this.colors = maxColors;
} }
@ -229,7 +231,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
protected override void FirstPass(ImageFrame<TPixel> source, int width, int height) protected override void FirstPass(ImageFrame<TPixel> source, int width, int height)
{ {
this.Build3DHistogram(source, width, height); this.Build3DHistogram(source, width, height);
this.Get3DMoments(source.MemoryAllocator); this.Get3DMoments(this.memoryAllocator);
this.BuildCube(); this.BuildCube();
} }
@ -465,13 +467,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
// Build up the 3-D color histogram // Build up the 3-D color histogram
// Loop through each row // Loop through each row
using (IMemoryOwner<Rgba32> rgbaBuffer = source.MemoryAllocator.Allocate<Rgba32>(source.Width)) using (IMemoryOwner<Rgba32> rgbaBuffer = this.memoryAllocator.Allocate<Rgba32>(source.Width))
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
Span<TPixel> row = source.GetPixelRowSpan(y); Span<TPixel> row = source.GetPixelRowSpan(y);
Span<Rgba32> rgbaSpan = rgbaBuffer.GetSpan(); Span<Rgba32> rgbaSpan = rgbaBuffer.GetSpan();
PixelOperations<TPixel>.Instance.ToRgba32(source.Configuration, row, rgbaSpan); PixelOperations<TPixel>.Instance.ToRgba32(source.GetConfiguration(), row, rgbaSpan);
ref Rgba32 scanBaseRef = ref MemoryMarshal.GetReference(rgbaSpan); ref Rgba32 scanBaseRef = ref MemoryMarshal.GetReference(rgbaSpan);
// And loop through each column // And loop through each column
@ -840,7 +842,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
private void BuildCube() private void BuildCube()
{ {
this.colorCube = new Box[this.colors]; this.colorCube = new Box[this.colors];
var vv = new double[this.colors]; Span<double> vv = stackalloc double[this.colors];
ref Box cube = ref this.colorCube[0]; ref Box cube = ref this.colorCube[0];
cube.RMin = cube.GMin = cube.BMin = cube.AMin = 0; cube.RMin = cube.GMin = cube.BMin = cube.AMin = 0;

9
src/ImageSharp/Processing/Processors/Quantization/WuQuantizer.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -68,13 +68,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// </summary> /// </summary>
public int MaxColors { get; } public int MaxColors { get; }
/// <param name="configuration"></param>
/// <inheritdoc /> /// <inheritdoc />
public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration) public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>(Configuration configuration)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
return new WuFrameQuantizer<TPixel>(configuration.MemoryAllocator, this); return new WuFrameQuantizer<TPixel>(configuration, this);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -83,9 +82,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
maxColors = maxColors.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors); maxColors = maxColors.Clamp(QuantizerConstants.MinColors, QuantizerConstants.MaxColors);
return new WuFrameQuantizer<TPixel>(configuration.MemoryAllocator, this, maxColors); return new WuFrameQuantizer<TPixel>(configuration, this, maxColors);
} }
private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null;
} }
} }

3
tests/Directory.Build.props

@ -24,7 +24,7 @@
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.props" /> <Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.props" />
<ItemGroup> <ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="Microsoft.NET.Test.Sdk" IsImplicitlyDefined="true" /> <PackageReference Include="Microsoft.NET.Test.Sdk" IsImplicitlyDefined="true" />
<PackageReference Include="xunit" IsImplicitlyDefined="true" /> <PackageReference Include="xunit" IsImplicitlyDefined="true" />
<PackageReference Include="xunit.runner.visualstudio" IsImplicitlyDefined="true" /> <PackageReference Include="xunit.runner.visualstudio" IsImplicitlyDefined="true" />
@ -32,7 +32,6 @@
<ItemGroup Condition="'$(codecov)' == 'true' AND '$(IsTestProject)' == 'true'"> <ItemGroup Condition="'$(codecov)' == 'true' AND '$(IsTestProject)' == 'true'">
<PackageReference Include="coverlet.collector" IsImplicitlyDefined="true" /> <PackageReference Include="coverlet.collector" IsImplicitlyDefined="true" />
<PackageReference Include="coverlet.msbuild" IsImplicitlyDefined="true" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

26
tests/Directory.Build.targets

@ -17,39 +17,25 @@
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" /> <Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" />
<!-- Tool versions for tool references across all projects --> <!-- Tool versions for tool references across all projects -->
<ItemGroup> <ItemGroup Condition="'$(IsTestProject)' == 'true'">
<!--dotnet tools does not have an x86 runner. You have to use separate SDKs--> <!--dotnet tools does not have an x86 runner. You have to use separate SDKs-->
<!--https://github.com/actions/setup-dotnet/issues/72--> <!--https://github.com/actions/setup-dotnet/issues/72-->
<DotNetCliToolReference Update="dotnet-xunit" Version="2.3.1" /> <DotNetCliToolReference Update="dotnet-xunit" Version="2.3.1" />
</ItemGroup> </ItemGroup>
<!--Code coverage specific settings-->
<!--https://github.com/tonerdo/coverlet-->
<PropertyGroup Condition="'$(codecov)' == 'true' AND '$(IsTestProject)' == 'true'">
<CollectCoverage>true</CollectCoverage>
<UseSourceLink>true</UseSourceLink>
<CoverletOutputFormat>opencover</CoverletOutputFormat>
<!--Output injects target framework into name despite explicit config. See build yml-->
<CoverletOutput>$(MSBuildThisFileDirectory)..\coverage.xml</CoverletOutput>
<!--Used by coverlet dues to reference issues with SixLabors.Core-->
<!--https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md#4-failed-to-resolve-assembly-during-instrumentation-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!--Test Dependencies--> <!--Test Dependencies-->
<PackageReference Update="BenchmarkDotNet" Version="0.12.0" /> <PackageReference Update="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Update="Colourful" Version="2.0.3" /> <PackageReference Update="Colourful" Version="2.0.3" />
<PackageReference Update="coverlet.collector" Version="1.1.0" PrivateAssets="All"/> <PackageReference Update="coverlet.collector" Version="1.2.0" PrivateAssets="All"/>
<PackageReference Update="coverlet.msbuild" Version="2.8.0" PrivateAssets="All"/>
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.14.4" /> <PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.14.4" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Update="Microsoft.DotNet.RemoteExecutor" Version="5.0.0-beta.20069.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0-preview-20200116-01" />
<PackageReference Update="Moq" Version="4.10.0" /> <PackageReference Update="Moq" Version="4.10.0" />
<PackageReference Update="Pfim" Version="0.9.1" /> <PackageReference Update="Pfim" Version="0.9.1" />
<PackageReference Update="System.Drawing.Common" Version="4.7.0" /> <PackageReference Update="System.Drawing.Common" Version="4.7.0" />
<!--TODO: Fix implicit conversion issues so we can move to 2.4.1--> <PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit" Version="2.3.1" /> <PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

3
tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs

@ -48,14 +48,11 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
TestImages.Jpeg.BenchmarkSuite.Lake_Small444YCbCr, TestImages.Jpeg.BenchmarkSuite.Lake_Small444YCbCr,
TestImages.Jpeg.BenchmarkSuite.BadRstProgressive518_Large444YCbCr, TestImages.Jpeg.BenchmarkSuite.BadRstProgressive518_Large444YCbCr,
#pragma warning disable SA1115 // Parameter should follow comma
// The scaled result for the large image "ExifGetString750Transform_Huge420YCbCr" // The scaled result for the large image "ExifGetString750Transform_Huge420YCbCr"
// is almost the same as the result for Jpeg420Exif, // is almost the same as the result for Jpeg420Exif,
// which proves that the execution time for the most common YCbCr 420 path scales linearly. // which proves that the execution time for the most common YCbCr 420 path scales linearly.
// TestImages.Jpeg.BenchmarkSuite.ExifGetString750Transform_Huge420YCbCr, // TestImages.Jpeg.BenchmarkSuite.ExifGetString750Transform_Huge420YCbCr,
TestImages.Jpeg.BenchmarkSuite.Jpeg420Exif_MidSizeYCbCr)] TestImages.Jpeg.BenchmarkSuite.Jpeg420Exif_MidSizeYCbCr)]
#pragma warning restore SA1115 // Parameter should follow comma
public string TestImage { get; set; } public string TestImage { get; set; }

24
tests/ImageSharp.Sandbox46/README.md

@ -1,24 +0,0 @@
## Purpose
This project aims to workaround certain .NET Core tooling issues in Visual Studio based developer workflow at the time of it's creation (January 2017):
- .NET Core Performance profiling is not possible neither with Visual Studio nor with JetBrains profilers
- ~~JetBrains Unit Test explorer does not work with .NET Core projects~~
## How does it work?
- By referencing .NET 4.5 dll-s created by net45 target's of ImageSharp projects. NOTE: These are not project references!
- By including test classes (and utility classes) of the `ImageSharp.Tests` project using MSBUILD `<Link>`
- Compiling `ImageSharp.Sandbox46` should trigger the compilation of ImageSharp subprojects using a manually defined solution dependencies
## How to profile unit tests
#### 1. With Visual Studio 2015 Test Runner
- **Do not** build `ImageSharp.Tests`
- Build `ImageSharp.Sandbox46`
- Use the [context menu in Test Explorer](https://adamprescott.net/2012/12/12/performance-profiling-for-unit-tests/)
NOTE:
There was no *Profile test* option in my VS Professional. Maybe things were messed by VS2017 RC installation. [This post suggests](http://stackoverflow.com/questions/32034375/profiling-tests-in-visual-studio-community-2015) it's necessary to own Premium or Ultimate edition of Visual Studio to profile tests.
#### 2. With JetBrains ReSharper Ultimate
- The `Sandbox46` project is no longer needed here. The classic `ImageSharp.Tests` project can be discovered by Unit Test Explorer.
- You can use [context menus](https://www.jetbrains.com/resharper/features/unit_testing.html) from your test class, or from unit Test Exporer/Unit Test Sessions windows.
![Context Menu](https://www.jetbrains.com/resharper/features/screenshots/100/unit_testing_profiling.png)

10
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj → tests/ImageSharp.Tests.ProfilingSandbox/ImageSharp.Tests.ProfilingSandbox.csproj

@ -2,14 +2,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<AssemblyName>SixLabors.ImageSharp.Sandbox46</AssemblyName> <AssemblyName>ImageSharp.Tests.ProfilingSandbox</AssemblyName>
<Description>A cross-platform library for processing of image files written in C#</Description> <Description>A cross-platform library for processing of image files written in C#</Description>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
<RootNamespace>SixLabors.ImageSharp.Sandbox46</RootNamespace> <RootNamespace>SixLabors.ImageSharp.Tests.ProfilingSandbox</RootNamespace>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier> <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks> <TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>
<StartupObject>SixLabors.ImageSharp.Sandbox46.Program</StartupObject> <StartupObject>SixLabors.ImageSharp.Tests.ProfilingSandbox.Program</StartupObject>
<!--Used to hide test project from dotnet test--> <!--Used to hide test project from dotnet test-->
<IsTestProject>false</IsTestProject> <IsTestProject>false</IsTestProject>
</PropertyGroup> </PropertyGroup>
@ -28,4 +28,8 @@
<PackageReference Include="System.Drawing.Common" /> <PackageReference Include="System.Drawing.Common" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ImageSharp.Tests\ImageSharp.Tests.csproj" />
</ItemGroup>
</Project> </Project>

10
tests/ImageSharp.Sandbox46/Program.cs → tests/ImageSharp.Tests.ProfilingSandbox/Program.cs

@ -1,16 +1,14 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Tests.Formats.Jpg;
using SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations; using SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations;
using SixLabors.ImageSharp.Tests.ProfilingBenchmarks; using SixLabors.ImageSharp.Tests.ProfilingBenchmarks;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Sandbox46 namespace SixLabors.ImageSharp.Tests.ProfilingSandbox
{ {
using System;
using SixLabors.ImageSharp.Tests.Formats.Jpg;
using Xunit.Abstractions;
public class Program public class Program
{ {
private class ConsoleOutput : ITestOutputHelper private class ConsoleOutput : ITestOutputHelper

2
tests/ImageSharp.Tests.ProfilingSandbox/README.md

@ -0,0 +1,2 @@
## ImageSharp.Tests.ProfilingSandbox
Helper project to run and profile unit tests or other "sandbox" code from a single .exe entry point.

0
tests/ImageSharp.Sandbox46/app.config → tests/ImageSharp.Tests.ProfilingSandbox/app.config

6
tests/ImageSharp.Tests/AssemblyInfo.cs

@ -0,0 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("ImageSharp.Tests.ProfilingSandbox")]

27
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs

@ -1,7 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@ -14,20 +16,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeBaselineJpeg<TPixel>(TestImageProvider<TPixel> provider) public void DecodeBaselineJpeg<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
if (SkipTest(provider)) static void RunTest(string providerDump)
{ {
// skipping to avoid OutOfMemoryException on CI TestImageProvider<TPixel> provider =
return; BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
}
using Image<TPixel> image = provider.GetImage(JpegDecoder);
image.DebugSave(provider);
using Image<TPixel> image = provider.GetImage(JpegDecoder); provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.DebugSave(provider); image.CompareToReferenceOutput(
GetImageComparer(provider),
provider,
appendPixelTypeToFileName: false);
}
provider.Utility.TestName = DecodeBaselineJpegOutputName; string providerDump = BasicSerializer.Serialize(provider);
image.CompareToReferenceOutput( RemoteExecutor.Invoke(RunTest, providerDump).Dispose();
this.GetImageComparer(provider),
provider,
appendPixelTypeToFileName: false);
} }
[Theory] [Theory]

27
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs

@ -1,7 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@ -16,20 +18,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeProgressiveJpeg<TPixel>(TestImageProvider<TPixel> provider) public void DecodeProgressiveJpeg<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
if (SkipTest(provider)) static void RunTest(string providerDump)
{ {
// skipping to avoid OutOfMemoryException on CI TestImageProvider<TPixel> provider =
return; BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
}
using Image<TPixel> image = provider.GetImage(JpegDecoder);
image.DebugSave(provider);
using Image<TPixel> image = provider.GetImage(JpegDecoder); provider.Utility.TestName = DecodeProgressiveJpegOutputName;
image.DebugSave(provider); image.CompareToReferenceOutput(
GetImageComparer(provider),
provider,
appendPixelTypeToFileName: false);
}
provider.Utility.TestName = DecodeProgressiveJpegOutputName; string dump = BasicSerializer.Serialize(provider);
image.CompareToReferenceOutput( RemoteExecutor.Invoke(RunTest, dump).Dispose();
this.GetImageComparer(provider),
provider,
appendPixelTypeToFileName: false);
} }
} }
} }

27
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -4,11 +4,12 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit; using Xunit;
@ -23,9 +24,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector;
private const float BaselineTolerance = 0.001F / 100; private const float BaselineTolerance = 0.001F / 100;
private const float ProgressiveTolerance = 0.2F / 100; private const float ProgressiveTolerance = 0.2F / 100;
private ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider) static JpegDecoderTests()
{
TestEnvironment.PrepareRemoteExecutor();
}
private static ImageComparer GetImageComparer<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
string file = provider.SourceFileOrDescription; string file = provider.SourceFileOrDescription;
@ -86,23 +93,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void JpegDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) public void JpegDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
if (SkipTest(provider)) static void RunTest(string providerDump)
{
return;
}
// For 32 bit test environments:
provider.Configuration.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling();
using (Image<TPixel> image = provider.GetImage(JpegDecoder))
{ {
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
using Image<TPixel> image = provider.GetImage(JpegDecoder);
image.DebugSave(provider); image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName; provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance), provider, appendPixelTypeToFileName: false); image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance), provider, appendPixelTypeToFileName: false);
} }
provider.Configuration.MemoryAllocator.ReleaseRetainedResources(); string dump = BasicSerializer.Serialize(provider);
RemoteExecutor.Invoke(RunTest, dump).Dispose();
} }
// DEBUG ONLY! // DEBUG ONLY!

48
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -201,6 +201,54 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
} }
} }
[Theory]
[WithBlankImages(1, 1, PixelTypes.A8, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Argb32, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Bgr565, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Bgra4444, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Byte4, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.HalfSingle, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.HalfVector2, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.HalfVector4, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.NormalizedByte2, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.NormalizedByte4, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.NormalizedShort4, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Rg32, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Rgba1010102, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Rgba32, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.RgbaVector, PngColorType.RgbWithAlpha, PngBitDepth.Bit16)]
[WithBlankImages(1, 1, PixelTypes.Short2, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Short4, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Rgb24, PngColorType.Rgb, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Bgr24, PngColorType.Rgb, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Bgra32, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.Rgb48, PngColorType.Rgb, PngBitDepth.Bit16)]
[WithBlankImages(1, 1, PixelTypes.Rgba64, PngColorType.RgbWithAlpha, PngBitDepth.Bit16)]
[WithBlankImages(1, 1, PixelTypes.Bgra5551, PngColorType.RgbWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.L8, PngColorType.Grayscale, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.L16, PngColorType.Grayscale, PngBitDepth.Bit16)]
[WithBlankImages(1, 1, PixelTypes.La16, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit8)]
[WithBlankImages(1, 1, PixelTypes.La32, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit16)]
public void InfersColorTypeAndBitDepth<TPixel>(TestImageProvider<TPixel> provider, PngColorType pngColorType, PngBitDepth pngBitDepth)
where TPixel : struct, IPixel<TPixel>
{
using (Stream stream = new MemoryStream())
{
var encoder = new PngEncoder();
encoder.Encode(provider.GetImage(), stream);
stream.Seek(0, SeekOrigin.Begin);
var decoder = new PngDecoder();
Image image = decoder.Decode(Configuration.Default, stream);
PngMetadata metadata = image.Metadata.GetPngMetadata();
Assert.Equal(pngColorType, metadata.ColorType);
Assert.Equal(pngBitDepth, metadata.BitDepth);
}
}
[Theory] [Theory]
[WithFile(TestImages.Png.Palette8Bpp, nameof(PaletteLargeOnly), PixelTypes.Rgba32)] [WithFile(TestImages.Png.Palette8Bpp, nameof(PaletteLargeOnly), PixelTypes.Rgba32)]
public void PaletteColorType_WuQuantizer<TPixel>(TestImageProvider<TPixel> provider, int paletteSize) public void PaletteColorType_WuQuantizer<TPixel>(TestImageProvider<TPixel> provider, int paletteSize)

1
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" /> <PackageReference Include="Magick.NET-Q16-AnyCPU" />
<PackageReference Include="Microsoft.DotNet.RemoteExecutor" />
<PackageReference Include="Moq" /> <PackageReference Include="Moq" />
<PackageReference Include="System.Drawing.Common" /> <PackageReference Include="System.Drawing.Common" />
</ItemGroup> </ItemGroup>

185
tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs

@ -4,39 +4,36 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
using System; using System;
using System.Buffers; using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.Win32;
using SixLabors.ImageSharp.Tests; using SixLabors.ImageSharp.Tests;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Memory.Tests namespace SixLabors.ImageSharp.Memory.Tests
{ {
// TODO: Re-enable memory-intensive tests with arcade RemoteExecutor:
// https://github.com/dotnet/runtime/blob/master/docs/project/writing-tests.md#remoteexecutor
public class ArrayPoolMemoryAllocatorTests public class ArrayPoolMemoryAllocatorTests
{ {
private const int MaxPooledBufferSizeInBytes = 2048; private const int MaxPooledBufferSizeInBytes = 2048;
private const int PoolSelectorThresholdInBytes = MaxPooledBufferSizeInBytes / 2; private const int PoolSelectorThresholdInBytes = MaxPooledBufferSizeInBytes / 2;
private MemoryAllocator MemoryAllocator { get; set; } =
new ArrayPoolMemoryAllocator(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes);
/// <summary> /// <summary>
/// Rent a buffer -> return it -> re-rent -> verify if it's span points to the previous location. /// Contains SUT for in-process tests.
/// </summary> /// </summary>
private bool CheckIsRentingPooledBuffer<T>(int length) private MemoryAllocatorFixture LocalFixture { get; } = new MemoryAllocatorFixture();
where T : struct
{
IMemoryOwner<T> buffer = this.MemoryAllocator.Allocate<T>(length);
ref T ptrToPrevPosition0 = ref buffer.GetReference();
buffer.Dispose();
buffer = this.MemoryAllocator.Allocate<T>(length); /// <summary>
bool sameBuffers = Unsafe.AreSame(ref ptrToPrevPosition0, ref buffer.GetReference()); /// Contains SUT for tests executed by <see cref="RemoteExecutor"/>,
buffer.Dispose(); /// recreated in each external process.
/// </summary>
private static MemoryAllocatorFixture StaticFixture { get; } = new MemoryAllocatorFixture();
return sameBuffers; static ArrayPoolMemoryAllocatorTests()
{
TestEnvironment.PrepareRemoteExecutor();
} }
public class BufferTests : BufferTestSuite public class BufferTests : BufferTestSuite
@ -78,21 +75,21 @@ namespace SixLabors.ImageSharp.Memory.Tests
[InlineData(MaxPooledBufferSizeInBytes - 1)] [InlineData(MaxPooledBufferSizeInBytes - 1)]
public void SmallBuffersArePooled_OfByte(int size) public void SmallBuffersArePooled_OfByte(int size)
{ {
Assert.True(this.CheckIsRentingPooledBuffer<byte>(size)); Assert.True(this.LocalFixture.CheckIsRentingPooledBuffer<byte>(size));
} }
[Theory(Skip = "Should be executed from a separate process.")] [Theory]
[InlineData(128 * 1024 * 1024)] [InlineData(128 * 1024 * 1024)]
[InlineData(MaxPooledBufferSizeInBytes + 1)] [InlineData(MaxPooledBufferSizeInBytes + 1)]
public void LargeBuffersAreNotPooled_OfByte(int size) public void LargeBuffersAreNotPooled_OfByte(int size)
{ {
if (!TestEnvironment.Is64BitProcess) static void RunTest(string sizeStr)
{ {
// can lead to OutOfMemoryException int size = int.Parse(sizeStr);
return; StaticFixture.CheckIsRentingPooledBuffer<byte>(size);
} }
Assert.False(this.CheckIsRentingPooledBuffer<byte>(size)); RemoteExecutor.Invoke(RunTest, size.ToString()).Dispose();
} }
[Fact] [Fact]
@ -100,21 +97,15 @@ namespace SixLabors.ImageSharp.Memory.Tests
{ {
int count = (MaxPooledBufferSizeInBytes / sizeof(LargeStruct)) - 1; int count = (MaxPooledBufferSizeInBytes / sizeof(LargeStruct)) - 1;
Assert.True(this.CheckIsRentingPooledBuffer<LargeStruct>(count)); Assert.True(this.LocalFixture.CheckIsRentingPooledBuffer<LargeStruct>(count));
} }
[Fact(Skip = "Should be executed from a separate process.")] [Fact]
public unsafe void LaregeBuffersAreNotPooled_OfBigValueType() public unsafe void LaregeBuffersAreNotPooled_OfBigValueType()
{ {
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
int count = (MaxPooledBufferSizeInBytes / sizeof(LargeStruct)) + 1; int count = (MaxPooledBufferSizeInBytes / sizeof(LargeStruct)) + 1;
Assert.False(this.CheckIsRentingPooledBuffer<LargeStruct>(count)); Assert.False(this.LocalFixture.CheckIsRentingPooledBuffer<LargeStruct>(count));
} }
[Theory] [Theory]
@ -122,12 +113,13 @@ namespace SixLabors.ImageSharp.Memory.Tests
[InlineData(AllocationOptions.Clean)] [InlineData(AllocationOptions.Clean)]
public void CleaningRequests_AreControlledByAllocationParameter_Clean(AllocationOptions options) public void CleaningRequests_AreControlledByAllocationParameter_Clean(AllocationOptions options)
{ {
using (IMemoryOwner<int> firstAlloc = this.MemoryAllocator.Allocate<int>(42)) MemoryAllocator memoryAllocator = this.LocalFixture.MemoryAllocator;
using (IMemoryOwner<int> firstAlloc = memoryAllocator.Allocate<int>(42))
{ {
firstAlloc.GetSpan().Fill(666); firstAlloc.GetSpan().Fill(666);
} }
using (IMemoryOwner<int> secondAlloc = this.MemoryAllocator.Allocate<int>(42, options)) using (IMemoryOwner<int> secondAlloc = memoryAllocator.Allocate<int>(42, options))
{ {
int expected = options == AllocationOptions.Clean ? 0 : 666; int expected = options == AllocationOptions.Clean ? 0 : 666;
Assert.Equal(expected, secondAlloc.GetSpan()[0]); Assert.Equal(expected, secondAlloc.GetSpan()[0]);
@ -139,7 +131,8 @@ namespace SixLabors.ImageSharp.Memory.Tests
[InlineData(true)] [InlineData(true)]
public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive) public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive)
{ {
IMemoryOwner<int> buffer = this.MemoryAllocator.Allocate<int>(32); MemoryAllocator memoryAllocator = this.LocalFixture.MemoryAllocator;
IMemoryOwner<int> buffer = memoryAllocator.Allocate<int>(32);
ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan()); ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan());
if (!keepBufferAlive) if (!keepBufferAlive)
@ -147,9 +140,9 @@ namespace SixLabors.ImageSharp.Memory.Tests
buffer.Dispose(); buffer.Dispose();
} }
this.MemoryAllocator.ReleaseRetainedResources(); memoryAllocator.ReleaseRetainedResources();
buffer = this.MemoryAllocator.Allocate<int>(32); buffer = memoryAllocator.Allocate<int>(32);
Assert.False(Unsafe.AreSame(ref ptrToPrev0, ref buffer.GetReference())); Assert.False(Unsafe.AreSame(ref ptrToPrev0, ref buffer.GetReference()));
} }
@ -157,86 +150,68 @@ namespace SixLabors.ImageSharp.Memory.Tests
[Fact] [Fact]
public void ReleaseRetainedResources_DisposingPreviouslyAllocatedBuffer_IsAllowed() public void ReleaseRetainedResources_DisposingPreviouslyAllocatedBuffer_IsAllowed()
{ {
IMemoryOwner<int> buffer = this.MemoryAllocator.Allocate<int>(32); MemoryAllocator memoryAllocator = this.LocalFixture.MemoryAllocator;
this.MemoryAllocator.ReleaseRetainedResources(); IMemoryOwner<int> buffer = memoryAllocator.Allocate<int>(32);
memoryAllocator.ReleaseRetainedResources();
buffer.Dispose(); buffer.Dispose();
} }
[Fact(Skip = "Should be executed from a separate process.")] [Fact]
public void AllocationOverLargeArrayThreshold_UsesDifferentPool() public void AllocationOverLargeArrayThreshold_UsesDifferentPool()
{ {
if (!TestEnvironment.Is64BitProcess) static void RunTest()
{ {
// can lead to OutOfMemoryException const int ArrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int);
return;
}
const int ArrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); IMemoryOwner<int> small = StaticFixture.MemoryAllocator.Allocate<int>(ArrayLengthThreshold - 1);
ref int ptr2Small = ref small.GetReference();
small.Dispose();
IMemoryOwner<int> small = this.MemoryAllocator.Allocate<int>(ArrayLengthThreshold - 1); IMemoryOwner<int> large = StaticFixture.MemoryAllocator.Allocate<int>(ArrayLengthThreshold + 1);
ref int ptr2Small = ref small.GetReference();
small.Dispose();
IMemoryOwner<int> large = this.MemoryAllocator.Allocate<int>(ArrayLengthThreshold + 1); Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.GetReference()));
}
Assert.False(Unsafe.AreSame(ref ptr2Small, ref large.GetReference())); RemoteExecutor.Invoke(RunTest).Dispose();
} }
[Fact(Skip = "Should be executed from a separate process.")] [Fact]
public void CreateWithAggressivePooling() public void CreateWithAggressivePooling()
{ {
if (!TestEnvironment.Is64BitProcess) static void RunTest()
{ {
// can lead to OutOfMemoryException StaticFixture.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithAggressivePooling();
return; Assert.True(StaticFixture.CheckIsRentingPooledBuffer<SmallStruct>(4096 * 4096));
} }
this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithAggressivePooling(); RemoteExecutor.Invoke(RunTest).Dispose();
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(4096 * 4096));
} }
[Fact(Skip = "Should be executed from a separate process.")] [Fact]
public void CreateDefault() public void CreateDefault()
{ {
if (!TestEnvironment.Is64BitProcess) static void RunTest()
{ {
// can lead to OutOfMemoryException StaticFixture.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault();
return;
}
this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault(); Assert.False(StaticFixture.CheckIsRentingPooledBuffer<SmallStruct>(2 * 4096 * 4096));
Assert.True(StaticFixture.CheckIsRentingPooledBuffer<SmallStruct>(2048 * 2048));
}
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2 * 4096 * 4096)); RemoteExecutor.Invoke(RunTest).Dispose();
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(2048 * 2048));
} }
[Fact] [Fact]
public void CreateWithModeratePooling() public void CreateWithModeratePooling()
{ {
if (!TestEnvironment.Is64BitProcess) static void RunTest()
{ {
// can lead to OutOfMemoryException StaticFixture.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling();
return; Assert.False(StaticFixture.CheckIsRentingPooledBuffer<SmallStruct>(2048 * 2048));
Assert.True(StaticFixture.CheckIsRentingPooledBuffer<SmallStruct>(1024 * 16));
} }
this.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling(); RemoteExecutor.Invoke(RunTest).Dispose();
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2048 * 2048));
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(1024 * 16));
}
[StructLayout(LayoutKind.Sequential)]
private struct Rgba32
{
private readonly uint dummy;
}
private const int SizeOfLargeStruct = MaxPooledBufferSizeInBytes / 5;
[StructLayout(LayoutKind.Explicit, Size = SizeOfLargeStruct)]
private struct LargeStruct
{
} }
[Theory] [Theory]
@ -244,7 +219,8 @@ namespace SixLabors.ImageSharp.Memory.Tests
[InlineData((int.MaxValue / SizeOfLargeStruct) + 1)] [InlineData((int.MaxValue / SizeOfLargeStruct) + 1)]
public void AllocateIncorrectAmount_ThrowsCorrect_ArgumentOutOfRangeException(int length) public void AllocateIncorrectAmount_ThrowsCorrect_ArgumentOutOfRangeException(int length)
{ {
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => this.MemoryAllocator.Allocate<LargeStruct>(length)); ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() =>
this.LocalFixture.MemoryAllocator.Allocate<LargeStruct>(length));
Assert.Equal("length", ex.ParamName); Assert.Equal("length", ex.ParamName);
} }
@ -252,8 +228,45 @@ namespace SixLabors.ImageSharp.Memory.Tests
[InlineData(-1)] [InlineData(-1)]
public void AllocateManagedByteBuffer_IncorrectAmount_ThrowsCorrect_ArgumentOutOfRangeException(int length) public void AllocateManagedByteBuffer_IncorrectAmount_ThrowsCorrect_ArgumentOutOfRangeException(int length)
{ {
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => this.MemoryAllocator.AllocateManagedByteBuffer(length)); ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() =>
this.LocalFixture.MemoryAllocator.AllocateManagedByteBuffer(length));
Assert.Equal("length", ex.ParamName); Assert.Equal("length", ex.ParamName);
} }
private class MemoryAllocatorFixture
{
public MemoryAllocator MemoryAllocator { get; set; } =
new ArrayPoolMemoryAllocator(MaxPooledBufferSizeInBytes, PoolSelectorThresholdInBytes);
/// <summary>
/// Rent a buffer -> return it -> re-rent -> verify if it's span points to the previous location.
/// </summary>
public bool CheckIsRentingPooledBuffer<T>(int length)
where T : struct
{
IMemoryOwner<T> buffer = this.MemoryAllocator.Allocate<T>(length);
ref T ptrToPrevPosition0 = ref buffer.GetReference();
buffer.Dispose();
buffer = this.MemoryAllocator.Allocate<T>(length);
bool sameBuffers = Unsafe.AreSame(ref ptrToPrevPosition0, ref buffer.GetReference());
buffer.Dispose();
return sameBuffers;
}
}
[StructLayout(LayoutKind.Sequential)]
private struct SmallStruct
{
private readonly uint dummy;
}
private const int SizeOfLargeStruct = MaxPooledBufferSizeInBytes / 5;
[StructLayout(LayoutKind.Explicit, Size = SizeOfLargeStruct)]
private struct LargeStruct
{
}
} }
} }

4
tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs

@ -125,7 +125,6 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Exif.Values
{ ExifTag.FocalPlaneYResolution }, { ExifTag.FocalPlaneYResolution },
{ ExifTag.ExposureIndex }, { ExifTag.ExposureIndex },
{ ExifTag.DigitalZoomRatio }, { ExifTag.DigitalZoomRatio },
{ ExifTag.LensInfo },
{ ExifTag.GPSAltitude }, { ExifTag.GPSAltitude },
{ ExifTag.GPSDOP }, { ExifTag.GPSDOP },
{ ExifTag.GPSSpeed }, { ExifTag.GPSSpeed },
@ -145,7 +144,8 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Exif.Values
{ ExifTag.GPSLongitude }, { ExifTag.GPSLongitude },
{ ExifTag.GPSTimestamp }, { ExifTag.GPSTimestamp },
{ ExifTag.GPSDestLatitude }, { ExifTag.GPSDestLatitude },
{ ExifTag.GPSDestLongitude } { ExifTag.GPSDestLongitude },
{ ExifTag.LensSpecification }
}; };
public static TheoryData<ExifTag> ShortTags => new TheoryData<ExifTag> public static TheoryData<ExifTag> ShortTags => new TheoryData<ExifTag>

90
tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTestsTPixel.cs

@ -30,8 +30,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void NormalBlendFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void NormalBlendFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.NormalSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.NormalSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -39,8 +39,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void NormalBlendFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void NormalBlendFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.NormalSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.NormalSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.NormalSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.NormalSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> MultiplyFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> MultiplyFunctionData = new TheoryData<object, object, float, object>
@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void MultiplyFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void MultiplyFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.MultiplySrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.MultiplySrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -79,8 +79,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void MultiplyFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void MultiplyFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.MultiplySrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.MultiplySrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.MultiplySrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.MultiplySrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> AddFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> AddFunctionData = new TheoryData<object, object, float, object>
@ -120,8 +120,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void AddFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void AddFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.AddSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.AddSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -129,8 +129,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void AddFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void AddFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.AddSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.AddSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.AddSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.AddSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> SubtractFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> SubtractFunctionData = new TheoryData<object, object, float, object>
@ -160,8 +160,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void SubtractFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void SubtractFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.SubtractSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.SubtractSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -169,8 +169,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void SubtractFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void SubtractFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.SubtractSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.SubtractSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -180,7 +180,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.SubtractSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.SubtractSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> ScreenFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> ScreenFunctionData = new TheoryData<object, object, float, object>
@ -200,8 +200,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void ScreenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void ScreenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.ScreenSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.ScreenSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -209,8 +209,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void ScreenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void ScreenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.ScreenSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.ScreenSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.ScreenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.ScreenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> DarkenFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> DarkenFunctionData = new TheoryData<object, object, float, object>
@ -240,8 +240,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void DarkenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void DarkenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.DarkenSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.DarkenSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -249,8 +249,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void DarkenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void DarkenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.DarkenSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.DarkenSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -260,7 +260,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.DarkenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.DarkenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> LightenFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> LightenFunctionData = new TheoryData<object, object, float, object>
@ -280,8 +280,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void LightenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void LightenFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.LightenSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.LightenSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -289,8 +289,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void LightenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void LightenFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.LightenSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.LightenSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -300,7 +300,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.LightenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.LightenSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> OverlayFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> OverlayFunctionData = new TheoryData<object, object, float, object>
@ -320,8 +320,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void OverlayFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void OverlayFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.OverlaySrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.OverlaySrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -329,8 +329,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void OverlayFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void OverlayFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.OverlaySrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.OverlaySrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -340,7 +340,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.OverlaySrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.OverlaySrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
public static TheoryData<object, object, float, object> HardLightFunctionData = new TheoryData<object, object, float, object> public static TheoryData<object, object, float, object> HardLightFunctionData = new TheoryData<object, object, float, object>
@ -360,8 +360,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void HardLightFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void HardLightFunction<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = PorterDuffFunctions.HardLightSrcOver((TPixel)back, source, amount); TPixel actual = PorterDuffFunctions.HardLightSrcOver(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -369,8 +369,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
public void HardLightFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected) public void HardLightFunctionBlender<TPixel>(TestPixel<TPixel> back, TestPixel<TPixel> source, float amount, TestPixel<TPixel> expected)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel actual = new DefaultPixelBlenders<TPixel>.HardLightSrcOver().Blend(back, source, amount); TPixel actual = new DefaultPixelBlenders<TPixel>.HardLightSrcOver().Blend(back.AsPixel(), source.AsPixel(), amount);
VectorAssert.Equal(expected, actual, 2); VectorAssert.Equal(expected.AsPixel(), actual, 2);
} }
[Theory] [Theory]
@ -380,7 +380,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders
{ {
var dest = new Span<TPixel>(new TPixel[1]); var dest = new Span<TPixel>(new TPixel[1]);
new DefaultPixelBlenders<TPixel>.HardLightSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); new DefaultPixelBlenders<TPixel>.HardLightSrcOver().Blend(this.Configuration, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount));
VectorAssert.Equal(expected, dest[0], 2); VectorAssert.Equal(expected.AsPixel(), dest[0], 2);
} }
} }
} }

20
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
using SixLabors.ImageSharp.ColorSpaces.Companding; using SixLabors.ImageSharp.ColorSpaces.Companding;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -274,20 +274,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
(s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan())); (s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan()));
} }
public static readonly TheoryData<IPixel> Generic_To_Data = new TheoryData<IPixel> public static readonly TheoryData<object> Generic_To_Data = new TheoryData<object>
{ {
default(Rgba32), new TestPixel<Rgba32>(),
default(Bgra32), new TestPixel<Bgra32>(),
default(Rgb24), new TestPixel<Rgb24>(),
default(L8), new TestPixel<L8>(),
default(L16), new TestPixel<L16>(),
default(Rgb48), new TestPixel<Rgb48>(),
default(Rgba64) new TestPixel<Rgba64>()
}; };
[Theory] [Theory]
[MemberData(nameof(Generic_To_Data))] [MemberData(nameof(Generic_To_Data))]
public void Generic_To<TDestPixel>(TDestPixel dummy) public void Generic_To<TDestPixel>(TestPixel<TDestPixel> dummy)
where TDestPixel : struct, IPixel<TDestPixel> where TDestPixel : struct, IPixel<TDestPixel>
{ {
const int Count = 2134; const int Count = 2134;

2
tests/ImageSharp.Tests/Primitives/ColorMatrixTests.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Primitives
ColorMatrix value1 = this.CreateAllTwos(); ColorMatrix value1 = this.CreateAllTwos();
ColorMatrix value2 = this.CreateAllThrees(); ColorMatrix value2 = this.CreateAllThrees();
ColorMatrix m; var m = default(ColorMatrix);
// First row // First row
m.M11 = (value1.M11 * value2.M11) + (value1.M12 * value2.M21) + (value1.M13 * value2.M31) + (value1.M14 * value2.M41); m.M11 = (value1.M11 * value2.M11) + (value1.M12 * value2.M21) + (value1.M13 * value2.M31) + (value1.M14 * value2.M41);

61
tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

@ -6,11 +6,12 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Processing.Processors.Convolution;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -18,6 +19,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{ {
public class BokehBlurTest public class BokehBlurTest
{ {
static BokehBlurTest()
{
TestEnvironment.PrepareRemoteExecutor();
}
private static readonly string Components10x2 = @" private static readonly string Components10x2 = @"
[[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j [[ 0.00451261+0.0165137j 0.02161237-0.00299122j 0.00387479-0.02682816j
-0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j -0.02752798-0.01788438j -0.03553877+0.0154543j -0.01428268+0.04224722j
@ -120,10 +126,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value) public void BokehBlurFilterProcessor<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunValidatingProcessorTest( static void RunTest(string providerDump, string infoDump)
x => x.BokehBlur(value.Radius, value.Components, value.Gamma), {
testOutputDetails: value.ToString(), TestImageProvider<TPixel> provider =
appendPixelTypeToFileName: false); BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest(
x => x.BokehBlur(value.Radius, value.Components, value.Gamma),
testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
} }
[Theory] [Theory]
@ -135,9 +152,18 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor_WorksWithAllPixelTypes<TPixel>(TestImageProvider<TPixel> provider) public void BokehBlurFilterProcessor_WorksWithAllPixelTypes<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunValidatingProcessorTest( static void RunTest(string providerDump)
x => x.BokehBlur(8, 2, 3), {
appendSourceFileOrDescription: false); TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.RunValidatingProcessorTest(
x => x.BokehBlur(8, 2, 3),
appendSourceFileOrDescription: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider))
.Dispose();
} }
[Theory] [Theory]
@ -145,15 +171,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
public void BokehBlurFilterProcessor_Bounded<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value) public void BokehBlurFilterProcessor_Bounded<TPixel>(TestImageProvider<TPixel> provider, BokehBlurInfo value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunValidatingProcessorTest( static void RunTest(string providerDump, string infoDump)
x => {
TestImageProvider<TPixel> provider =
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
BokehBlurInfo value = BasicSerializer.Deserialize<BokehBlurInfo>(infoDump);
provider.RunValidatingProcessorTest(
x =>
{ {
Size size = x.GetCurrentSize(); Size size = x.GetCurrentSize();
var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2); var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2);
x.BokehBlur(value.Radius, value.Components, value.Gamma, bounds); x.BokehBlur(value.Radius, value.Components, value.Gamma, bounds);
}, },
testOutputDetails: value.ToString(), testOutputDetails: value.ToString(),
appendPixelTypeToFileName: false); appendPixelTypeToFileName: false);
}
RemoteExecutor
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
} }
} }
} }

8
tests/ImageSharp.Tests/Processing/Processors/Effects/PixelShaderTest.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunValidatingProcessorTest( provider.RunValidatingProcessorTest(
x => x.ApplyPixelShaderProcessor( x => x.ProcessPixelRowsAsVector4(
span => span =>
{ {
for (int i = 0; i < span.Length; i++) for (int i = 0; i < span.Length; i++)
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunRectangleConstrainedValidatingProcessorTest( provider.RunRectangleConstrainedValidatingProcessorTest(
(x, rect) => x.ApplyPixelShaderProcessor( (x, rect) => x.ProcessPixelRowsAsVector4(
span => span =>
{ {
for (int i = 0; i < span.Length; i++) for (int i = 0; i < span.Length; i++)
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunValidatingProcessorTest( provider.RunValidatingProcessorTest(
c => c.ApplyPixelShaderProcessor( c => c.ProcessPixelRowsAsVector4(
(span, offset) => (span, offset) =>
{ {
int y = offset.Y; int y = offset.Y;
@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.RunRectangleConstrainedValidatingProcessorTest( provider.RunRectangleConstrainedValidatingProcessorTest(
(c, rect) => c.ApplyPixelShaderProcessor( (c, rect) => c.ProcessPixelRowsAsVector4(
(span, offset) => (span, offset) =>
{ {
int y = offset.Y; int y = offset.Y;

28
tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs

@ -9,8 +9,8 @@ namespace SixLabors.ImageSharp.Tests
{ {
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageProvider{TPixel}"/> instances which return the image produced by the given test class member method /// Triggers passing <see cref="TestImageProvider{TPixel}"/> instances which return the image produced by the given test class member method
/// <see cref="TestImageProvider{TPixel}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TPixel}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter.
/// The parameter of the factory method must be a <see cref="GenericFactory{TPixel}"/> instance /// The parameter of the factory method must be a <see cref="GenericFactory{TPixel}"/> instance.
/// </summary> /// </summary>
public class WithMemberFactoryAttribute : ImageDataAttributeBase public class WithMemberFactoryAttribute : ImageDataAttributeBase
{ {
@ -18,11 +18,11 @@ namespace SixLabors.ImageSharp.Tests
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageProvider{TPixel}"/> instances which return the image produced by the given test class member method /// Triggers passing <see cref="TestImageProvider{TPixel}"/> instances which return the image produced by the given test class member method
/// <see cref="TestImageProvider{TPixel}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TPixel}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter.
/// </summary> /// </summary>
/// <param name="memberMethodName">The name of the static test class which returns the image</param> /// <param name="memberMethodName">The name of the static test class which returns the image.</param>
/// <param name="pixelTypes">The requested pixel types</param> /// <param name="pixelTypes">The requested pixel types.</param>
/// <param name="additionalParameters">Additional theory parameter values</param> /// <param name="additionalParameters">Additional theory parameter values.</param>
public WithMemberFactoryAttribute(string memberMethodName, PixelTypes pixelTypes, params object[] additionalParameters) public WithMemberFactoryAttribute(string memberMethodName, PixelTypes pixelTypes, params object[] additionalParameters)
: base(null, pixelTypes, additionalParameters) : base(null, pixelTypes, additionalParameters)
{ {
@ -31,21 +31,9 @@ namespace SixLabors.ImageSharp.Tests
protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType)
{ {
MethodInfo m = testMethod.DeclaringType.GetMethod(this.memberMethodName); return new object[] { testMethod.DeclaringType.FullName, this.memberMethodName };
Type[] args = factoryType.GetGenericArguments();
Type colorType = args.Single();
Type imgType = typeof(Image<>).MakeGenericType(colorType);
Type funcType = typeof(Func<>).MakeGenericType(imgType);
MethodInfo genericMethod = m.MakeGenericMethod(args);
Delegate d = genericMethod.CreateDelegate(funcType);
return new object[] { d };
} }
protected override string GetFactoryMethodName(MethodInfo testMethod) => "Lambda"; protected override string GetFactoryMethodName(MethodInfo testMethod) => "Lambda";
} }
} }

100
tests/ImageSharp.Tests/TestUtilities/BasicSerializer.cs

@ -0,0 +1,100 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.TestUtilities
{
/// <summary>
/// RemoteExecutor can only execute static methods, which can only consume string arguments,
/// because data is being passed on command line interface. This utility allows serialization
/// of <see cref="IXunitSerializable"/> types to strings.
/// </summary>
internal class BasicSerializer : IXunitSerializationInfo
{
private readonly Dictionary<string, string> map = new Dictionary<string, string>();
public const char Separator = ':';
private string DumpToString(Type type)
{
using var ms = new MemoryStream();
using var writer = new StreamWriter(ms);
writer.WriteLine(type.FullName);
foreach (KeyValuePair<string, string> kv in this.map)
{
writer.WriteLine($"{kv.Key}{Separator}{kv.Value}");
}
writer.Flush();
byte[] data = ms.ToArray();
return System.Convert.ToBase64String(data);
}
private Type LoadDump(string dump)
{
byte[] data = System.Convert.FromBase64String(dump);
using var ms = new MemoryStream(data);
using var reader = new StreamReader(ms);
var type = Type.GetType(reader.ReadLine());
for (string s = reader.ReadLine(); s != null; s = reader.ReadLine())
{
string[] kv = s.Split(Separator);
this.map[kv[0]] = kv[1];
}
return type;
}
public static string Serialize(IXunitSerializable serializable)
{
var serializer = new BasicSerializer();
serializable.Serialize(serializer);
return serializer.DumpToString(serializable.GetType());
}
public static T Deserialize<T>(string dump)
where T : IXunitSerializable
{
var serializer = new BasicSerializer();
Type type = serializer.LoadDump(dump);
var result = (T)Activator.CreateInstance(type);
result.Deserialize(serializer);
return result;
}
public void AddValue(string key, object value, Type type = null)
{
Guard.NotNull(key, nameof(key));
if (value == null)
{
return;
}
type ??= value.GetType();
this.map[key] = TypeDescriptor.GetConverter(type).ConvertToInvariantString(value);
}
public object GetValue(string key, Type type)
{
Guard.NotNull(key, nameof(key));
if (!this.map.TryGetValue(key, out string str))
{
return type.IsValueType ? Activator.CreateInstance(type) : null;
}
return TypeDescriptor.GetConverter(type).ConvertFromInvariantString(str);
}
public T GetValue<T>(string key) => (T)this.GetValue(key, typeof(T));
}
}

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
var bBuffer = new Rgba64[width]; var bBuffer = new Rgba64[width];
var differences = new List<PixelDifference>(); var differences = new List<PixelDifference>();
Configuration configuration = expected.Configuration; Configuration configuration = expected.GetConfiguration();
for (int y = 0; y < actual.Height; y++) for (int y = 0; y < actual.Height; y++)
{ {

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
float totalDifference = 0F; float totalDifference = 0F;
var differences = new List<PixelDifference>(); var differences = new List<PixelDifference>();
Configuration configuration = expected.Configuration; Configuration configuration = expected.GetConfiguration();
for (int y = 0; y < actual.Height; y++) for (int y = 0; y < actual.Height; y++)
{ {

3
tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs

@ -5,10 +5,11 @@ using System;
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
public abstract partial class TestImageProvider<TPixel> public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
{ {
private class BasicTestPatternProvider : BlankProvider private class BasicTestPatternProvider : BlankProvider
{ {

2
tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs

@ -7,7 +7,7 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
public abstract partial class TestImageProvider<TPixel> public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private class BlankProvider : TestImageProvider<TPixel>, IXunitSerializable private class BlankProvider : TestImageProvider<TPixel>, IXunitSerializable

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save