diff --git a/.editorconfig b/.editorconfig
index 33fd0577a8..753a4dbc2a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -122,7 +122,7 @@ dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
# File header preferences
-file_header_template = Copyright (c) Six Labors.\nLicensed under the Apache License, Version 2.0.
+file_header_template = Copyright (c) Six Labors.\nLicensed under the Six Labors Split License.
# SA1636: File header copyright text should match
# Justification: .editorconfig supports file headers. If this is changed to a value other than "none", a stylecop.json file will need to added to the project.
# dotnet_diagnostic.SA1636.severity = none
diff --git a/.gitattributes b/.gitattributes
index 355b64dce1..2fdea90e17 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -130,3 +130,4 @@
*.ppm filter=lfs diff=lfs merge=lfs -text
*.pnm filter=lfs diff=lfs merge=lfs -text
*.wbmp filter=lfs diff=lfs merge=lfs -text
+*.exr filter=lfs diff=lfs merge=lfs -text
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index ec9258883d..729f66a6b6 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,5 +1,8 @@
blank_issues_enabled: false
contact_links:
+ - name: Questions
+ url: https://github.com/SixLabors/ImageSharp/discussions/categories/q-a
+ about: Ask the community for help.
- name: Feature Request
url: https://github.com/SixLabors/ImageSharp/discussions/categories/ideas
about: Share ideas for new features for this project.
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000000..5ace4600a1
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,6 @@
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 16f8ebb065..1a57ec1ed9 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -20,12 +20,13 @@ jobs:
sdk-preview: true
runtime: -x64
codecov: false
- - os: macos-latest
- framework: net7.0
- sdk: 7.0.x
- sdk-preview: true
- runtime: -x64
- codecov: false
+ # Temp disabled due to runtime preview issues.
+ #- os: macos-latest
+ # framework: net7.0
+ # sdk: 7.0.x
+ # sdk-preview: true
+ # runtime: -x64
+ # codecov: false
- os: windows-latest
framework: net7.0
sdk: 7.0.x
@@ -58,7 +59,7 @@ jobs:
git config --global core.longpaths true
- name: Git Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
@@ -68,7 +69,7 @@ jobs:
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Git Setup LFS Cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
@@ -81,7 +82,7 @@ jobs:
uses: NuGet/setup-nuget@v1
- name: NuGet Setup Cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: nuget-cache
with:
path: ~/.nuget
@@ -89,13 +90,21 @@ jobs:
restore-keys: ${{ runner.os }}-nuget-
- name: DotNet Setup
- uses: actions/setup-dotnet@v1
+ if: ${{ matrix.options.sdk-preview != true }}
+ uses: actions/setup-dotnet@v2
with:
include-prerelease: true
dotnet-version: |
- 7.0.x
6.0.x
+ - name: DotNet Setup Preview
+ if: ${{ matrix.options.sdk-preview == true }}
+ uses: actions/setup-dotnet@v2
+ with:
+ include-prerelease: true
+ dotnet-version: |
+ 7.0.x
+
- name: DotNet Build
if: ${{ matrix.options.sdk-preview != true }}
shell: pwsh
@@ -127,7 +136,7 @@ jobs:
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
- name: Export Failed Output
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v3
if: failure()
with:
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
@@ -148,7 +157,7 @@ jobs:
git config --global core.longpaths true
- name: Git Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
@@ -157,7 +166,7 @@ jobs:
uses: NuGet/setup-nuget@v1
- name: NuGet Setup Cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: nuget-cache
with:
path: ~/.nuget
diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml
index 3f8a820313..85ff42b74b 100644
--- a/.github/workflows/code-coverage.yml
+++ b/.github/workflows/code-coverage.yml
@@ -24,7 +24,7 @@ jobs:
git config --global core.longpaths true
- name: Git Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
@@ -34,7 +34,7 @@ jobs:
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Git Setup LFS Cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
@@ -47,7 +47,7 @@ jobs:
uses: NuGet/setup-nuget@v1
- name: NuGet Setup Cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
id: nuget-cache
with:
path: ~/.nuget
@@ -55,7 +55,7 @@ jobs:
restore-keys: ${{ runner.os }}-nuget-
- name: DotNet Setup
- uses: actions/setup-dotnet@v1
+ uses: actions/setup-dotnet@v2
with:
dotnet-version: |
6.0.x
@@ -74,14 +74,14 @@ jobs:
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
- name: Export Failed Output
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v3
if: failure()
with:
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
path: tests/Images/ActualOutput/
- name: Codecov Update
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v3
if: matrix.options.codecov == true && startsWith(github.repository, 'SixLabors')
with:
flags: unittests
diff --git a/ImageSharp.sln b/ImageSharp.sln
index fbf1ca24ba..3ea3160a79 100644
--- a/ImageSharp.sln
+++ b/ImageSharp.sln
@@ -28,9 +28,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{1799
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{FBE8C1AD-5AEC-4514-9B64-091D8E145865}"
ProjectSection(SolutionItems) = preProject
- .github\ISSUE_TEMPLATE\commercial-bug-report.md = .github\ISSUE_TEMPLATE\commercial-bug-report.md
+ .github\ISSUE_TEMPLATE\commercial-bug-report.yml = .github\ISSUE_TEMPLATE\commercial-bug-report.yml
.github\ISSUE_TEMPLATE\config.yml = .github\ISSUE_TEMPLATE\config.yml
- .github\ISSUE_TEMPLATE\oss-bug-report.md = .github\ISSUE_TEMPLATE\oss-bug-report.md
+ .github\ISSUE_TEMPLATE\oss-bug-report.yml = .github\ISSUE_TEMPLATE\oss-bug-report.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
@@ -648,10 +648,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tga", "Tga", "{5DFC394F-136
EndProjectSection
EndProject
Global
- GlobalSection(SharedMSBuildProjectFiles) = preSolution
- shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2aa31a1f-142c-43f4-8687-09abca4b3a26}*SharedItemsImports = 5
- shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
- EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
@@ -707,6 +703,10 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}
EndGlobalSection
+ GlobalSection(SharedMSBuildProjectFiles) = preSolution
+ shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2aa31a1f-142c-43f4-8687-09abca4b3a26}*SharedItemsImports = 5
+ shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
+ EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
diff --git a/LICENSE b/LICENSE
index 8d5852d374..a68eb67834 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,201 +1,43 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
+Six Labors Split License
+Version 1.0, June 2022
+Copyright (c) Six Labors
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- 1. Definitions.
+1. Definitions.
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source
+ code, documentation source, and configuration files.
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including
+ but not limited to compiled object code, generated documentation, and conversions to other media types.
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
+ "Work" (or "Works") shall mean any Six Labors software made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work.
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
+ "Direct Package Dependency" shall mean any Work in Source or Object form that is installed directly by You.
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
+ "Transitive Package Dependency" shall mean any Work in Object form that is installed indirectly by a third party
+ dependency unrelated to Six Labors.
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
+2. License
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
+ Works in Source or Object form are split licensed and may be licensed under the Apache License, Version 2.0 or a
+ Six Labors Commercial Use License.
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
+ Licenses are granted based upon You meeting the qualified criteria as stated. Once granted,
+ You must reference the granted license only in all documentation.
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
+ Works in Source or Object form are licensed to You under the Apache License, Version 2.0 if.
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
+ - You are consuming the Work in for use in software licensed under an Open Source or Source Available license.
+ - You are consuming the Work as a Transitive Package Dependency.
+ - You are consuming the Work as a Direct Package Dependency in the capacity of a For-profit company/individual with
+ less than 1M USD annual gross revenue.
+ - You are consuming the Work as a Direct Package Dependency in the capacity of a Non-profit organization
+ or Registered Charity.
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright (c) Six Labors
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ For all other scenarios, Works in Source or Object form are licensed to You under the Six Labors Commercial License
+ which may be purchased by visiting https://sixlabors.com/pricing/.
diff --git a/README.md b/README.md
index 6c669fb787..34466eccd7 100644
--- a/README.md
+++ b/README.md
@@ -9,30 +9,29 @@ SixLabors.ImageSharp
[](https://github.com/SixLabors/ImageSharp/actions)
[](https://codecov.io/gh/SixLabors/ImageSharp)
-[](https://opensource.org/licenses/Apache-2.0)
+[](https://github.com/SixLabors/ImageSharp/blob/main/LICENSE)
[](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)
### **ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API.
-ImageSharp is a new, fully featured, fully managed, cross-platform, 2D graphics library. Designed to simplify image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.
+ImageSharp is a new, fully featured, fully managed, cross-platform, 2D graphics library.
+Designed to simplify image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.
ImageSharp is designed from the ground up to be flexible and extensible. The library provides API endpoints for common image processing operations and the building blocks to allow for the development of additional operations.
-Built against [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
+Built against [.NET 6](https://docs.microsoft.com/en-us/dotnet/standard/net-standard), ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
## License
-- ImageSharp is licensed under the [Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0)
-- An alternative Six Labors License can be purchased **for projects and applications requiring developer support**.
-Please visit https://sixlabors.com/pricing for details.
+- ImageSharp is licensed under the [Six Labors Split License, Version 1.0](https://github.com/SixLabors/ImageSharp/blob/main/LICENSE)
## Support Six Labors
Support the efforts of the development of the Six Labors projects.
- - [Purchase a Commercial Support License :heart:](https://sixlabors.com/pricing/)
+ - [Purchase a Commercial License :heart:](https://sixlabors.com/pricing/)
- [Become a sponsor via GitHub Sponsors :heart:]( https://github.com/sponsors/SixLabors)
- [Become a sponsor via Open Collective :heart:](https://opencollective.com/sixlabors)
@@ -43,7 +42,7 @@ Support the efforts of the development of the Six Labors projects.
## Questions
-- Do you have questions? We are happy to help! Simply purchase a [Six Labors License](https://sixlabors.com/pricing) for developer support. Please do not open issues for questions or misuse our [Discussions Forum](https://github.com/SixLabors/ImageSharp/discussions).
+- Do you have questions? Please [join our Discussions Forum](https://github.com/SixLabors/ImageSharp/discussions/categories/q-a). Do not open issues for questions.
- For feature ideas please [join our Discussions Forum](https://github.com/SixLabors/ImageSharp/discussions/categories/ideas) and we'll be happy to discuss.
- Please read our [Contribution Guide](https://github.com/SixLabors/ImageSharp/blob/main/.github/CONTRIBUTING.md) before opening issues or pull requests!
@@ -63,9 +62,9 @@ Install stable releases via Nuget; development releases are available via MyGet.
If you prefer, you can compile ImageSharp yourself (please do and help!)
-- Using [Visual Studio 2019](https://visualstudio.microsoft.com/vs/)
+- Using [Visual Studio 2022](https://visualstudio.microsoft.com/vs/)
- Make sure you have the latest version installed
- - Make sure you have [the .NET 5 SDK](https://www.microsoft.com/net/core#windows) installed
+ - Make sure you have [the .NET 6 SDK](https://www.microsoft.com/net/core#windows) installed
Alternatively, you can work from command line and/or with a lightweight editor on **both Linux/Unix and Windows**:
diff --git a/shared-infrastructure b/shared-infrastructure
index 59ce17f5a4..c0e0353c1e 160000
--- a/shared-infrastructure
+++ b/shared-infrastructure
@@ -1 +1 @@
-Subproject commit 59ce17f5a4e1f956811133f41add7638e74c2836
+Subproject commit c0e0353c1ee89398def0ccdc3e945380034fbea8
diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
index 829c6155db..8a7046c9ad 100644
--- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
+++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs
index 2323b5ba78..7db2b7f963 100644
--- a/src/ImageSharp/Advanced/AotCompilerTools.cs
+++ b/src/ImageSharp/Advanced/AotCompilerTools.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Diagnostics.CodeAnalysis;
diff --git a/src/ImageSharp/Advanced/IConfigurationProvider.cs b/src/ImageSharp/Advanced/IConfigurationProvider.cs
index 9c9d2a942b..da1f6c1fd2 100644
--- a/src/ImageSharp/Advanced/IConfigurationProvider.cs
+++ b/src/ImageSharp/Advanced/IConfigurationProvider.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Advanced/IImageVisitor.cs b/src/ImageSharp/Advanced/IImageVisitor.cs
index ccff180266..2f2aa7a318 100644
--- a/src/ImageSharp/Advanced/IImageVisitor.cs
+++ b/src/ImageSharp/Advanced/IImageVisitor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Threading;
using System.Threading.Tasks;
diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs
index 948abe0be1..d6d5415363 100644
--- a/src/ImageSharp/Advanced/IPixelSource.cs
+++ b/src/ImageSharp/Advanced/IPixelSource.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Advanced/IRowIntervalOperation.cs b/src/ImageSharp/Advanced/IRowIntervalOperation.cs
index cc7072ff9d..33a9bc40c2 100644
--- a/src/ImageSharp/Advanced/IRowIntervalOperation.cs
+++ b/src/ImageSharp/Advanced/IRowIntervalOperation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs b/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
index a76624e1ac..b1e6dae314 100644
--- a/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
+++ b/src/ImageSharp/Advanced/IRowIntervalOperation{TBuffer}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Advanced/IRowOperation.cs b/src/ImageSharp/Advanced/IRowOperation.cs
index 122296172c..8a7d62e0f5 100644
--- a/src/ImageSharp/Advanced/IRowOperation.cs
+++ b/src/ImageSharp/Advanced/IRowOperation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs b/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
index 5e1562a794..cf491c82f4 100644
--- a/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
+++ b/src/ImageSharp/Advanced/IRowOperation{TBuffer}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Advanced/ParallelExecutionSettings.cs b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
index e1f36d9d64..01b1a1538a 100644
--- a/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
+++ b/src/ImageSharp/Advanced/ParallelExecutionSettings.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Threading.Tasks;
diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
index 3c2b9fd2c8..d2d01ebdfa 100644
--- a/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
+++ b/src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Advanced/ParallelRowIterator.cs b/src/ImageSharp/Advanced/ParallelRowIterator.cs
index e787b7cfc5..d37a76951e 100644
--- a/src/ImageSharp/Advanced/ParallelRowIterator.cs
+++ b/src/ImageSharp/Advanced/ParallelRowIterator.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Advanced/PreserveAttribute.cs b/src/ImageSharp/Advanced/PreserveAttribute.cs
index a16b30e235..d543a043c8 100644
--- a/src/ImageSharp/Advanced/PreserveAttribute.cs
+++ b/src/ImageSharp/Advanced/PreserveAttribute.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Advanced
{
diff --git a/src/ImageSharp/Color/Color.Conversions.cs b/src/ImageSharp/Color/Color.Conversions.cs
index 5c10bfaa09..2e8f4100e4 100644
--- a/src/ImageSharp/Color/Color.Conversions.cs
+++ b/src/ImageSharp/Color/Color.Conversions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Color/Color.NamedColors.cs b/src/ImageSharp/Color/Color.NamedColors.cs
index 609191d5ed..8a01b9e6ec 100644
--- a/src/ImageSharp/Color/Color.NamedColors.cs
+++ b/src/ImageSharp/Color/Color.NamedColors.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Color/Color.WebSafePalette.cs b/src/ImageSharp/Color/Color.WebSafePalette.cs
index 1cffb841c4..40275bad47 100644
--- a/src/ImageSharp/Color/Color.WebSafePalette.cs
+++ b/src/ImageSharp/Color/Color.WebSafePalette.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Color/Color.WernerPalette.cs b/src/ImageSharp/Color/Color.WernerPalette.cs
index 52299ae8fd..6083112dba 100644
--- a/src/ImageSharp/Color/Color.WernerPalette.cs
+++ b/src/ImageSharp/Color/Color.WernerPalette.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs
index cd05833617..d8fb348913 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/src/ImageSharp/Color/Color.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs
index c1b9aab379..b72a2eecd4 100644
--- a/src/ImageSharp/ColorSpaces/CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/CieLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs
index 7722b705eb..899c7d8dbc 100644
--- a/src/ImageSharp/ColorSpaces/CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/CieLch.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs
index ed8e72fc9d..2a41fd490c 100644
--- a/src/ImageSharp/ColorSpaces/CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs
index 6b69b90888..a45042ba85 100644
--- a/src/ImageSharp/ColorSpaces/CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/CieLuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs
index 5e3b444acd..9306606db9 100644
--- a/src/ImageSharp/ColorSpaces/CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyy.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs
index ceffd727d1..e52904c558 100644
--- a/src/ImageSharp/ColorSpaces/CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/CieXyz.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs
index fb8efad634..cd2899ee7d 100644
--- a/src/ImageSharp/ColorSpaces/Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Cmyk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
index 440aa41853..db2c21448c 100644
--- a/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/GammaCompanding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
index 5cd89abfd6..211005ac8f 100644
--- a/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/LCompanding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs b/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
index 957c076875..372dc7ac2c 100644
--- a/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/Rec2020Companding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs b/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
index 8b511aa1c1..f753d16dc7 100644
--- a/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/Rec709Companding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
index dc6c960aa5..1337af702c 100644
--- a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
index 0d3568a2a8..62fa445c5e 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/CieConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
index f39d5049c4..60ae18b5c9 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Adapt.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.ColorSpaces.Conversion
{
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
index 86075e0023..1a7c627db5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
index da2e808444..06ff11b1ec 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
index 7f100428bc..5752cb9b11 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLchuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
index 1c831f7144..486924b9aa 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLuv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
index 0adac22019..603308751c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyy.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
index b069bb72c6..242392acc0 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
index 5fa5ec8b13..664511be9a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Cmyk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
index f880767069..666a6b03cf 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsl.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
index 6d784575c6..615a26e36c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Hsv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
index 147ffba70c..ad2fbd626d 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.HunterLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
index 7156ac82fa..c317c8e8bb 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.LinearRgb.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
index 7f44a3e4b7..be36c46dc3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Lms.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
index ce09b1148f..cfb6d3b76b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.Rgb.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
index 126f1eb21c..db6dc21338 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.YCbCr.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
index f565e6aa69..001719046f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
index e91c83624e..ceb7f24ad3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
index 36dd2445e1..728d7cd222 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyChromaticityCoordinates.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
index 0b6ca40716..6485da0762 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CIeLchToCieLabConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
index 25542f5598..0aefeda856 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieLchConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
index 34354efe54..3634ebe99b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLabToCieXyzConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
index 052db0e77b..fc064a6ded 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLchuvToCieLuvConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
index 13644b0922..d69fb46970 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieLchuvConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
index 12c65105fc..0b4a4a9b85 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieLuvToCieXyzConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
index ea021d73ca..5db91eb754 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndCieXyyConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
index 7ed2d78d8d..5bb394dfa7 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndHunterLabConverterBase.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
index 22f081ccd6..533d94465b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzAndLmsConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
index 5f16a82a4a..641ee8077b 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLabConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
index 031d96e71d..48843dd81f 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToCieLuvConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
index 0b70f8c85c..494c7b3c89 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
index f6ee2b0d85..c9ae11ffcc 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
index 72f543442c..20a03fb41d 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CmykAndRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
index d0e0da756c..c5a599e9e5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HslAndRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
index f005e025a1..de187ee593 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HsvAndRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
index f120d6f3dd..a804d1d5f5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
index 556334b4dc..8a406cb333 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
index c52a91e6f0..f124fdd807 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
index 7e9e3210a8..ea5ef2bc11 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
index 056f896088..5ce09802c4 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/RgbToLinearRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
index 3f90e8d719..727c89dd7a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/YCbCrAndRgbConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
index b787c48b30..703b3a7487 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/IChromaticAdaptation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
index f69868760a..ea0dfbb4c9 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/LmsAdaptationMatrix.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
index 2a03b54e7f..a38626020d 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
index 6dec4d735a..b107aacafa 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/VonKriesChromaticAdaptation.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
index f9b268307c..9c2bc6f026 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
index 7d42759aee..f608baac48 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
index d57936e354..b675fe53d5 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
index 5d556fa0db..6df9a17b9a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
index 996b72094f..ad869a75b0 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
index 8140d24dba..236da1fd02 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces.Companding;
diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs
index 740752e6d8..98f9bdb7c2 100644
--- a/src/ImageSharp/ColorSpaces/Hsl.cs
+++ b/src/ImageSharp/ColorSpaces/Hsl.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs
index d29e4b5b7b..a44aebbb17 100644
--- a/src/ImageSharp/ColorSpaces/Hsv.cs
+++ b/src/ImageSharp/ColorSpaces/Hsv.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs
index a36ad4b9e0..c3d808c6c3 100644
--- a/src/ImageSharp/ColorSpaces/HunterLab.cs
+++ b/src/ImageSharp/ColorSpaces/HunterLab.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Illuminants.cs b/src/ImageSharp/ColorSpaces/Illuminants.cs
index f22ab9cd0b..4f14982faa 100644
--- a/src/ImageSharp/ColorSpaces/Illuminants.cs
+++ b/src/ImageSharp/ColorSpaces/Illuminants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.ColorSpaces
{
diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs
index 245dbbd0f1..5dffea678a 100644
--- a/src/ImageSharp/ColorSpaces/LinearRgb.cs
+++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs
index e0068c92fc..7ca8c3cf0f 100644
--- a/src/ImageSharp/ColorSpaces/Lms.cs
+++ b/src/ImageSharp/ColorSpaces/Lms.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs
index 900f71b2c4..4902d98fd6 100644
--- a/src/ImageSharp/ColorSpaces/Rgb.cs
+++ b/src/ImageSharp/ColorSpaces/Rgb.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
index 07f76e58c7..00cca02dab 100644
--- a/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
+++ b/src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.ColorSpaces.Companding;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs
index b39fe30252..cb4d7d091b 100644
--- a/src/ImageSharp/ColorSpaces/YCbCr.cs
+++ b/src/ImageSharp/ColorSpaces/YCbCr.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/ByteOrder.cs b/src/ImageSharp/Common/ByteOrder.cs
index cc38f1cdee..603384b3a7 100644
--- a/src/ImageSharp/Common/ByteOrder.cs
+++ b/src/ImageSharp/Common/ByteOrder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs
index 90f33fdf7e..0a3378939e 100644
--- a/src/ImageSharp/Common/Constants.cs
+++ b/src/ImageSharp/Common/Constants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
index 6a54ce5485..0c50410a54 100644
--- a/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
+++ b/src/ImageSharp/Common/Exceptions/ImageFormatException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
index dc4f4f1088..51c238af85 100644
--- a/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
+++ b/src/ImageSharp/Common/Exceptions/ImageProcessingException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
index e4713e237c..7b48c9fe94 100644
--- a/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
+++ b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
index f3a1ea0f57..beab6586be 100644
--- a/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
+++ b/src/ImageSharp/Common/Exceptions/UnknownImageFormatException.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
index 9bf0a1fbe6..883468abd5 100644
--- a/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Threading.Tasks;
diff --git a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
index caef4ac928..b49e1234fa 100644
--- a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if !SUPPORTS_ENCODING_STRING
using System;
diff --git a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
index c6560f8c3b..92fba789ac 100644
--- a/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/EnumerableExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
index 8746989b38..e21d9e96b1 100644
--- a/src/ImageSharp/Common/Extensions/StreamExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Common/Helpers/ColorNumerics.cs b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
index 6f225b1109..8ae344a4eb 100644
--- a/src/ImageSharp/Common/Helpers/ColorNumerics.cs
+++ b/src/ImageSharp/Common/Helpers/ColorNumerics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs
index f438ca9e24..6e1ed21817 100644
--- a/src/ImageSharp/Common/Helpers/DebugGuard.cs
+++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Common/Helpers/EnumUtils.cs b/src/ImageSharp/Common/Helpers/EnumUtils.cs
index 089aba337c..d6bead6408 100644
--- a/src/ImageSharp/Common/Helpers/EnumUtils.cs
+++ b/src/ImageSharp/Common/Helpers/EnumUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/ExifResolutionValues.cs b/src/ImageSharp/Common/Helpers/ExifResolutionValues.cs
index b6a628608b..704f75d4f7 100644
--- a/src/ImageSharp/Common/Helpers/ExifResolutionValues.cs
+++ b/src/ImageSharp/Common/Helpers/ExifResolutionValues.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Common.Helpers
{
diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs
index 0f6efcb3c4..fb18392f38 100644
--- a/src/ImageSharp/Common/Helpers/Guard.cs
+++ b/src/ImageSharp/Common/Helpers/Guard.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/HexConverter.cs b/src/ImageSharp/Common/Helpers/HexConverter.cs
index c55e9bbd9d..27a5a40f6d 100644
--- a/src/ImageSharp/Common/Helpers/HexConverter.cs
+++ b/src/ImageSharp/Common/Helpers/HexConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/InliningOptions.cs b/src/ImageSharp/Common/Helpers/InliningOptions.cs
index 1ae880787e..a6c6d021c6 100644
--- a/src/ImageSharp/Common/Helpers/InliningOptions.cs
+++ b/src/ImageSharp/Common/Helpers/InliningOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
// Uncomment this for verbose profiler results. DO NOT PUSH TO MAIN!
// #define PROFILING
diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs
index 7de838bc94..c149cc7b6c 100644
--- a/src/ImageSharp/Common/Helpers/Numerics.cs
+++ b/src/ImageSharp/Common/Helpers/Numerics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
@@ -75,6 +75,12 @@ namespace SixLabors.ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Modulo8(int x) => x & 7;
+ ///
+ /// Calculates % 8
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static nint Modulo8(nint x) => x & 7;
+
///
/// Fast (x mod m) calculator, with the restriction that
/// should be power of 2.
@@ -968,7 +974,7 @@ namespace SixLabors.ImageSharp
/// Tells whether input value is outside of the given range.
///
/// Value.
- /// Mininum value, inclusive.
+ /// Minimum value, inclusive.
/// Maximum value, inclusive.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOutOfRange(int value, int min, int max)
diff --git a/src/ImageSharp/Common/Helpers/RuntimeEnvironment.cs b/src/ImageSharp/Common/Helpers/RuntimeEnvironment.cs
index 5525d3de50..925925ff95 100644
--- a/src/ImageSharp/Common/Helpers/RuntimeEnvironment.cs
+++ b/src/ImageSharp/Common/Helpers/RuntimeEnvironment.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs
index 049c611851..0d27ea437f 100644
--- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs
+++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs
index 0c2b1d5082..cb85a550db 100644
--- a/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs
+++ b/src/ImageSharp/Common/Helpers/Shuffle/IPad3Shuffle4.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs
index 61e99890e7..d5c8e17ece 100644
--- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs
+++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle3.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs
index 3ecad3c5d9..d50aab005c 100644
--- a/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs
+++ b/src/ImageSharp/Common/Helpers/Shuffle/IShuffle4Slice3.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
index 75555f88a5..7e878677f1 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
index 0abc0e26da..336ff3abc2 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
index 15133770f6..c035ac72f7 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
index b1d84c3e06..ceeba0faae 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs
index b8c14698af..fb62cb77e5 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs
index abf9e9fed0..db86afd64d 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.Shuffle.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.cs b/src/ImageSharp/Common/Helpers/SimdUtils.cs
index 29068a82c9..0384cc4edb 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Diagnostics;
diff --git a/src/ImageSharp/Common/Helpers/TestHelpers.cs b/src/ImageSharp/Common/Helpers/TestHelpers.cs
index 33aa81f3d5..159fd95d3a 100644
--- a/src/ImageSharp/Common/Helpers/TestHelpers.cs
+++ b/src/ImageSharp/Common/Helpers/TestHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Common.Helpers
{
diff --git a/src/ImageSharp/Common/Helpers/TolerantMath.cs b/src/ImageSharp/Common/Helpers/TolerantMath.cs
index d1d3f21740..f244a9169d 100644
--- a/src/ImageSharp/Common/Helpers/TolerantMath.cs
+++ b/src/ImageSharp/Common/Helpers/TolerantMath.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Common/Helpers/UnitConverter.cs b/src/ImageSharp/Common/Helpers/UnitConverter.cs
index 7ea64aa624..ba7bdb0e03 100644
--- a/src/ImageSharp/Common/Helpers/UnitConverter.cs
+++ b/src/ImageSharp/Common/Helpers/UnitConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Common/Tuples/Octet{T}.cs b/src/ImageSharp/Common/Tuples/Octet{T}.cs
index aaecafd09d..08fa639435 100644
--- a/src/ImageSharp/Common/Tuples/Octet{T}.cs
+++ b/src/ImageSharp/Common/Tuples/Octet{T}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Compression/Zlib/Adler32.cs b/src/ImageSharp/Compression/Zlib/Adler32.cs
index 1f3cbbca64..7c3b4ae18b 100644
--- a/src/ImageSharp/Compression/Zlib/Adler32.cs
+++ b/src/ImageSharp/Compression/Zlib/Adler32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Compression/Zlib/Crc32.Lut.cs b/src/ImageSharp/Compression/Zlib/Crc32.Lut.cs
index 059bd9f312..304372d2de 100644
--- a/src/ImageSharp/Compression/Zlib/Crc32.Lut.cs
+++ b/src/ImageSharp/Compression/Zlib/Crc32.Lut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Compression.Zlib
{
diff --git a/src/ImageSharp/Compression/Zlib/Crc32.cs b/src/ImageSharp/Compression/Zlib/Crc32.cs
index 075d6112a1..0d900cc178 100644
--- a/src/ImageSharp/Compression/Zlib/Crc32.cs
+++ b/src/ImageSharp/Compression/Zlib/Crc32.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Compression/Zlib/DeflateCompressionLevel.cs b/src/ImageSharp/Compression/Zlib/DeflateCompressionLevel.cs
index 2edf76e7d5..e483435f60 100644
--- a/src/ImageSharp/Compression/Zlib/DeflateCompressionLevel.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflateCompressionLevel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Compression.Zlib
{
diff --git a/src/ImageSharp/Compression/Zlib/DeflateThrowHelper.cs b/src/ImageSharp/Compression/Zlib/DeflateThrowHelper.cs
index 02590ca253..d334a02449 100644
--- a/src/ImageSharp/Compression/Zlib/DeflateThrowHelper.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflateThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Compression/Zlib/Deflater.cs b/src/ImageSharp/Compression/Zlib/Deflater.cs
index 7ff8342aac..78736d6204 100644
--- a/src/ImageSharp/Compression/Zlib/Deflater.cs
+++ b/src/ImageSharp/Compression/Zlib/Deflater.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Compression/Zlib/DeflaterConstants.cs b/src/ImageSharp/Compression/Zlib/DeflaterConstants.cs
index 30bd75ffcd..507952fd36 100644
--- a/src/ImageSharp/Compression/Zlib/DeflaterConstants.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflaterConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
//
using System;
diff --git a/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs b/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs
index 02fa5bf58d..a77c22bf81 100644
--- a/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflaterEngine.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
index 27a8d5671d..6536601129 100644
--- a/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs b/src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs
index d949ddf38c..9ba9d34b13 100644
--- a/src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Compression/Zlib/DeflaterPendingBuffer.cs b/src/ImageSharp/Compression/Zlib/DeflaterPendingBuffer.cs
index 8f2c8d3987..b24150faf4 100644
--- a/src/ImageSharp/Compression/Zlib/DeflaterPendingBuffer.cs
+++ b/src/ImageSharp/Compression/Zlib/DeflaterPendingBuffer.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs b/src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs
index 44883665ab..5bccf470d4 100644
--- a/src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs
+++ b/src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs b/src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs
index f4b0543b84..ed5766435d 100644
--- a/src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs
+++ b/src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs
index 3e021dda8d..ea1c4eea23 100644
--- a/src/ImageSharp/Configuration.cs
+++ b/src/ImageSharp/Configuration.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Concurrent;
diff --git a/src/ImageSharp/Diagnostics/MemoryDiagnostics.cs b/src/ImageSharp/Diagnostics/MemoryDiagnostics.cs
index 89f18cff61..274486cec5 100644
--- a/src/ImageSharp/Diagnostics/MemoryDiagnostics.cs
+++ b/src/ImageSharp/Diagnostics/MemoryDiagnostics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Bmp/BmpArrayFileHeader.cs b/src/ImageSharp/Formats/Bmp/BmpArrayFileHeader.cs
index 2338572476..88dee6100a 100644
--- a/src/ImageSharp/Formats/Bmp/BmpArrayFileHeader.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpArrayFileHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
index 7801e48a91..1b73d8b189 100644
--- a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpColorSpace.cs b/src/ImageSharp/Formats/Bmp/BmpColorSpace.cs
new file mode 100644
index 0000000000..0bab53a2be
--- /dev/null
+++ b/src/ImageSharp/Formats/Bmp/BmpColorSpace.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+// ReSharper disable InconsistentNaming
+namespace SixLabors.ImageSharp.Formats.Bmp
+{
+ ///
+ /// Enum for the different color spaces.
+ ///
+ internal enum BmpColorSpace
+ {
+ ///
+ /// This value implies that endpoints and gamma values are given in the appropriate fields.
+ ///
+ LCS_CALIBRATED_RGB = 0,
+
+ ///
+ /// The Windows default color space ('Win ').
+ ///
+ LCS_WINDOWS_COLOR_SPACE = 1466527264,
+
+ ///
+ /// Specifies that the bitmap is in sRGB color space ('sRGB').
+ ///
+ LCS_sRGB = 1934772034,
+
+ ///
+ /// This value indicates that bV5ProfileData points to the file name of the profile to use (gamma and endpoints values are ignored).
+ ///
+ PROFILE_LINKED = 1279872587,
+
+ ///
+ /// This value indicates that bV5ProfileData points to a memory buffer that contains the profile to be used (gamma and endpoints values are ignored).
+ ///
+ PROFILE_EMBEDDED = 1296188740
+ }
+}
diff --git a/src/ImageSharp/Formats/Bmp/BmpCompression.cs b/src/ImageSharp/Formats/Bmp/BmpCompression.cs
index 50d1ae46db..2749462e3c 100644
--- a/src/ImageSharp/Formats/Bmp/BmpCompression.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs b/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs
index 0bec34ffb2..cff81d58e3 100644
--- a/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpConstants.cs b/src/ImageSharp/Formats/Bmp/BmpConstants.cs
index 0b9499eeb3..e4954bb1e7 100644
--- a/src/ImageSharp/Formats/Bmp/BmpConstants.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
index e764489388..15d5b9a087 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index a22a04980c..3a96c40223 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -11,6 +11,7 @@ using SixLabors.ImageSharp.Common.Helpers;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
+using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Bmp
@@ -185,7 +186,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
break;
default:
- BmpThrowHelper.ThrowNotSupportedException("Does not support this kind of bitmap files.");
+ BmpThrowHelper.ThrowNotSupportedException("ImageSharp does not support this kind of bitmap files.");
break;
}
@@ -1199,6 +1200,13 @@ namespace SixLabors.ImageSharp.Formats.Bmp
private void ReadInfoHeader()
{
Span buffer = stackalloc byte[BmpInfoHeader.MaxHeaderSize];
+ long infoHeaderStart = this.stream.Position;
+
+ // Resolution is stored in PPM.
+ this.metadata = new ImageMetadata
+ {
+ ResolutionUnits = PixelResolutionUnit.PixelsPerMeter
+ };
// Read the header size.
this.stream.Read(buffer, 0, BmpInfoHeader.HeaderSizeSize);
@@ -1271,36 +1279,45 @@ namespace SixLabors.ImageSharp.Formats.Bmp
infoHeaderType = BmpInfoHeaderType.Os2Version2;
this.infoHeader = BmpInfoHeader.ParseOs2Version2(buffer);
}
- else if (headerSize >= BmpInfoHeader.SizeV4)
+ else if (headerSize == BmpInfoHeader.SizeV4)
{
- // >= 108 bytes
- infoHeaderType = headerSize == BmpInfoHeader.SizeV4 ? BmpInfoHeaderType.WinVersion4 : BmpInfoHeaderType.WinVersion5;
+ // == 108 bytes
+ infoHeaderType = BmpInfoHeaderType.WinVersion4;
this.infoHeader = BmpInfoHeader.ParseV4(buffer);
}
+ else if (headerSize > BmpInfoHeader.SizeV4)
+ {
+ // > 108 bytes
+ infoHeaderType = BmpInfoHeaderType.WinVersion5;
+ this.infoHeader = BmpInfoHeader.ParseV5(buffer);
+ if (this.infoHeader.ProfileData != 0 && this.infoHeader.ProfileSize != 0)
+ {
+ // Read color profile.
+ long streamPosition = this.stream.Position;
+ byte[] iccProfileData = new byte[this.infoHeader.ProfileSize];
+ this.stream.Position = infoHeaderStart + this.infoHeader.ProfileData;
+ this.stream.Read(iccProfileData);
+ this.metadata.IccProfile = new IccProfile(iccProfileData);
+ this.stream.Position = streamPosition;
+ }
+ }
else
{
BmpThrowHelper.ThrowNotSupportedException($"ImageSharp does not support this BMP file. HeaderSize '{headerSize}'.");
}
- // Resolution is stored in PPM.
- var meta = new ImageMetadata
- {
- ResolutionUnits = PixelResolutionUnit.PixelsPerMeter
- };
if (this.infoHeader.XPelsPerMeter > 0 && this.infoHeader.YPelsPerMeter > 0)
{
- meta.HorizontalResolution = this.infoHeader.XPelsPerMeter;
- meta.VerticalResolution = this.infoHeader.YPelsPerMeter;
+ this.metadata.HorizontalResolution = this.infoHeader.XPelsPerMeter;
+ this.metadata.VerticalResolution = this.infoHeader.YPelsPerMeter;
}
else
{
// Convert default metadata values to PPM.
- meta.HorizontalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetadata.DefaultHorizontalResolution));
- meta.VerticalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetadata.DefaultVerticalResolution));
+ this.metadata.HorizontalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetadata.DefaultHorizontalResolution));
+ this.metadata.VerticalResolution = Math.Round(UnitConverter.InchToMeter(ImageMetadata.DefaultVerticalResolution));
}
- this.metadata = meta;
-
short bitsPerPixel = this.infoHeader.BitsPerPixel;
this.bmpMetadata = this.metadata.GetBmpMetadata();
this.bmpMetadata.InfoHeaderType = infoHeaderType;
@@ -1370,9 +1387,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
int colorMapSizeBytes = -1;
if (this.infoHeader.ClrUsed == 0)
{
- if (this.infoHeader.BitsPerPixel == 1
- || this.infoHeader.BitsPerPixel == 4
- || this.infoHeader.BitsPerPixel == 8)
+ if (this.infoHeader.BitsPerPixel is 1 or 4 or 8)
{
switch (this.fileMarkerType)
{
@@ -1424,7 +1439,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
int skipAmount = this.fileHeader.Offset - (int)this.stream.Position;
if ((skipAmount + (int)this.stream.Position) > this.stream.Length)
{
- BmpThrowHelper.ThrowInvalidImageContentException("Invalid fileheader offset found. Offset is greater than the stream length.");
+ BmpThrowHelper.ThrowInvalidImageContentException("Invalid file header offset found. Offset is greater than the stream length.");
}
if (skipAmount > 0)
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
index f256ed9f81..25669b3f9b 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index 6384074df3..f71275b7cc 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -1,8 +1,9 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
+using System.Buffers.Binary;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
@@ -79,9 +80,10 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// A bitmap v4 header will only be written, if the user explicitly wants support for transparency.
/// In this case the compression type BITFIELDS will be used.
+ /// If the image contains a color profile, a bitmap v5 header is written, which is needed to write this info.
/// Otherwise a bitmap v3 header will be written, which is supported by almost all decoders.
///
- private readonly bool writeV4Header;
+ private BmpInfoHeaderType infoHeaderType;
///
/// The quantizer for reducing the color count for 8-Bit, 4-Bit and 1-Bit images.
@@ -97,8 +99,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
this.memoryAllocator = memoryAllocator;
this.bitsPerPixel = options.BitsPerPixel;
- this.writeV4Header = options.SupportTransparency;
this.quantizer = options.Quantizer ?? KnownQuantizers.Octree;
+ this.infoHeaderType = options.SupportTransparency ? BmpInfoHeaderType.WinVersion4 : BmpInfoHeaderType.WinVersion3;
}
///
@@ -123,7 +125,62 @@ namespace SixLabors.ImageSharp.Formats.Bmp
int bytesPerLine = 4 * (((image.Width * bpp) + 31) / 32);
this.padding = bytesPerLine - (int)(image.Width * (bpp / 8F));
- // Set Resolution.
+ int colorPaletteSize = 0;
+ if (this.bitsPerPixel == BmpBitsPerPixel.Pixel8)
+ {
+ colorPaletteSize = ColorPaletteSize8Bit;
+ }
+ else if (this.bitsPerPixel == BmpBitsPerPixel.Pixel4)
+ {
+ colorPaletteSize = ColorPaletteSize4Bit;
+ }
+ else if (this.bitsPerPixel == BmpBitsPerPixel.Pixel1)
+ {
+ colorPaletteSize = ColorPaletteSize1Bit;
+ }
+
+ byte[] iccProfileData = null;
+ int iccProfileSize = 0;
+ if (metadata.IccProfile != null)
+ {
+ this.infoHeaderType = BmpInfoHeaderType.WinVersion5;
+ iccProfileData = metadata.IccProfile.ToByteArray();
+ iccProfileSize = iccProfileData.Length;
+ }
+
+ int infoHeaderSize = this.infoHeaderType switch
+ {
+ BmpInfoHeaderType.WinVersion3 => BmpInfoHeader.SizeV3,
+ BmpInfoHeaderType.WinVersion4 => BmpInfoHeader.SizeV4,
+ BmpInfoHeaderType.WinVersion5 => BmpInfoHeader.SizeV5,
+ _ => BmpInfoHeader.SizeV3
+ };
+
+ BmpInfoHeader infoHeader = this.CreateBmpInfoHeader(image.Width, image.Height, infoHeaderSize, bpp, bytesPerLine, metadata, iccProfileData);
+
+ Span buffer = stackalloc byte[infoHeaderSize];
+
+ this.WriteBitmapFileHeader(stream, infoHeaderSize, colorPaletteSize, iccProfileSize, infoHeader, buffer);
+ this.WriteBitmapInfoHeader(stream, infoHeader, buffer, infoHeaderSize);
+ this.WriteImage(stream, image.Frames.RootFrame);
+ this.WriteColorProfile(stream, iccProfileData, buffer);
+
+ stream.Flush();
+ }
+
+ ///
+ /// Creates the bitmap information header.
+ ///
+ /// The width of the image.
+ /// The height of the image.
+ /// Size of the information header.
+ /// The bits per pixel.
+ /// The bytes per line.
+ /// The metadata.
+ /// The icc profile data.
+ /// The bitmap information header.
+ private BmpInfoHeader CreateBmpInfoHeader(int width, int height, int infoHeaderSize, short bpp, int bytesPerLine, ImageMetadata metadata, byte[] iccProfileData)
+ {
int hResolution = 0;
int vResolution = 0;
@@ -154,20 +211,19 @@ namespace SixLabors.ImageSharp.Formats.Bmp
}
}
- int infoHeaderSize = this.writeV4Header ? BmpInfoHeader.SizeV4 : BmpInfoHeader.SizeV3;
var infoHeader = new BmpInfoHeader(
headerSize: infoHeaderSize,
- height: image.Height,
- width: image.Width,
+ height: height,
+ width: width,
bitsPerPixel: bpp,
planes: 1,
- imageSize: image.Height * bytesPerLine,
+ imageSize: height * bytesPerLine,
clrUsed: 0,
clrImportant: 0,
xPelsPerMeter: hResolution,
yPelsPerMeter: vResolution);
- if (this.writeV4Header && this.bitsPerPixel == BmpBitsPerPixel.Pixel32)
+ if ((this.infoHeaderType is BmpInfoHeaderType.WinVersion4 or BmpInfoHeaderType.WinVersion5) && this.bitsPerPixel == BmpBitsPerPixel.Pixel32)
{
infoHeader.AlphaMask = Rgba32AlphaMask;
infoHeader.RedMask = Rgba32RedMask;
@@ -176,45 +232,79 @@ namespace SixLabors.ImageSharp.Formats.Bmp
infoHeader.Compression = BmpCompression.BitFields;
}
- int colorPaletteSize = 0;
- if (this.bitsPerPixel == BmpBitsPerPixel.Pixel8)
+ if (this.infoHeaderType is BmpInfoHeaderType.WinVersion5 && metadata.IccProfile != null)
{
- colorPaletteSize = ColorPaletteSize8Bit;
+ infoHeader.ProfileSize = iccProfileData.Length;
+ infoHeader.CsType = BmpColorSpace.PROFILE_EMBEDDED;
+ infoHeader.Intent = BmpRenderingIntent.LCS_GM_IMAGES;
}
- else if (this.bitsPerPixel == BmpBitsPerPixel.Pixel4)
- {
- colorPaletteSize = ColorPaletteSize4Bit;
- }
- else if (this.bitsPerPixel == BmpBitsPerPixel.Pixel1)
+
+ return infoHeader;
+ }
+
+ ///
+ /// Writes the color profile to the stream.
+ ///
+ /// The stream to write to.
+ /// The color profile data.
+ /// The buffer.
+ private void WriteColorProfile(Stream stream, byte[] iccProfileData, Span buffer)
+ {
+ if (iccProfileData != null)
{
- colorPaletteSize = ColorPaletteSize1Bit;
+ // The offset, in bytes, from the beginning of the BITMAPV5HEADER structure to the start of the profile data.
+ int streamPositionAfterImageData = (int)stream.Position - BmpFileHeader.Size;
+ stream.Write(iccProfileData);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer, streamPositionAfterImageData);
+ stream.Position = BmpFileHeader.Size + 112;
+ stream.Write(buffer.Slice(0, 4));
}
+ }
+ ///
+ /// Writes the bitmap file header.
+ ///
+ /// The stream to write the header to.
+ /// Size of the bitmap information header.
+ /// Size of the color palette.
+ /// The size in bytes of the color profile.
+ /// The information header to write.
+ /// The buffer to write to.
+ private void WriteBitmapFileHeader(Stream stream, int infoHeaderSize, int colorPaletteSize, int iccProfileSize, BmpInfoHeader infoHeader, Span buffer)
+ {
var fileHeader = new BmpFileHeader(
type: BmpConstants.TypeMarkers.Bitmap,
- fileSize: BmpFileHeader.Size + infoHeaderSize + colorPaletteSize + infoHeader.ImageSize,
+ fileSize: BmpFileHeader.Size + infoHeaderSize + colorPaletteSize + iccProfileSize + infoHeader.ImageSize,
reserved: 0,
offset: BmpFileHeader.Size + infoHeaderSize + colorPaletteSize);
- Span buffer = stackalloc byte[infoHeaderSize];
fileHeader.WriteTo(buffer);
-
stream.Write(buffer, 0, BmpFileHeader.Size);
+ }
- if (this.writeV4Header)
- {
- infoHeader.WriteV4Header(buffer);
- }
- else
+ ///
+ /// Writes the bitmap information header.
+ ///
+ /// The stream to write info header into.
+ /// The information header.
+ /// The buffer.
+ /// Size of the information header.
+ private void WriteBitmapInfoHeader(Stream stream, BmpInfoHeader infoHeader, Span buffer, int infoHeaderSize)
+ {
+ switch (this.infoHeaderType)
{
- infoHeader.WriteV3Header(buffer);
+ case BmpInfoHeaderType.WinVersion3:
+ infoHeader.WriteV3Header(buffer);
+ break;
+ case BmpInfoHeaderType.WinVersion4:
+ infoHeader.WriteV4Header(buffer);
+ break;
+ case BmpInfoHeaderType.WinVersion5:
+ infoHeader.WriteV5Header(buffer);
+ break;
}
stream.Write(buffer, 0, infoHeaderSize);
-
- this.WriteImage(stream, image.Frames.RootFrame);
-
- stream.Flush();
}
///
diff --git a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs
index acbcdaef3a..25254d2103 100644
--- a/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpFileHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
@@ -57,10 +57,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
public int Offset { get; }
- public static BmpFileHeader Parse(Span data)
- {
- return MemoryMarshal.Cast(data)[0];
- }
+ public static BmpFileHeader Parse(Span data) => MemoryMarshal.Cast(data)[0];
public void WriteTo(Span buffer)
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpFileMarkerType.cs b/src/ImageSharp/Formats/Bmp/BmpFileMarkerType.cs
index 882ccd12a2..eb6640ba94 100644
--- a/src/ImageSharp/Formats/Bmp/BmpFileMarkerType.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpFileMarkerType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpFormat.cs b/src/ImageSharp/Formats/Bmp/BmpFormat.cs
index d92a73104e..95820043a4 100644
--- a/src/ImageSharp/Formats/Bmp/BmpFormat.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
index b380486a3f..9c920f2bfc 100644
--- a/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs
index 0d0c05c9f4..823569b8ad 100644
--- a/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
@@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
int greenMask = 0,
int blueMask = 0,
int alphaMask = 0,
- int csType = 0,
+ BmpColorSpace csType = 0,
int redX = 0,
int redY = 0,
int redZ = 0,
@@ -94,7 +94,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp
int blueZ = 0,
int gammeRed = 0,
int gammeGreen = 0,
- int gammeBlue = 0)
+ int gammeBlue = 0,
+ BmpRenderingIntent intent = BmpRenderingIntent.Invalid,
+ int profileData = 0,
+ int profileSize = 0,
+ int reserved = 0)
{
this.HeaderSize = headerSize;
this.Width = width;
@@ -124,6 +128,10 @@ namespace SixLabors.ImageSharp.Formats.Bmp
this.GammaRed = gammeRed;
this.GammaGreen = gammeGreen;
this.GammaBlue = gammeBlue;
+ this.Intent = intent;
+ this.ProfileData = profileData;
+ this.ProfileSize = profileSize;
+ this.Reserved = reserved;
}
///
@@ -211,7 +219,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// Gets or sets the Color space type. Not used yet.
///
- public int CsType { get; set; }
+ public BmpColorSpace CsType { get; set; }
///
/// Gets or sets the X coordinate of red endpoint. Not used yet.
@@ -273,21 +281,38 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
public int GammaBlue { get; set; }
+ ///
+ /// Gets or sets the rendering intent for bitmap.
+ ///
+ public BmpRenderingIntent Intent { get; set; }
+
+ ///
+ /// Gets or sets the offset, in bytes, from the beginning of the BITMAPV5HEADER structure to the start of the profile data.
+ ///
+ public int ProfileData { get; set; }
+
+ ///
+ /// Gets or sets the size, in bytes, of embedded profile data.
+ ///
+ public int ProfileSize { get; set; }
+
+ ///
+ /// Gets or sets the reserved value.
+ ///
+ public int Reserved { get; set; }
+
///
/// Parses the BITMAPCOREHEADER (BMP Version 2) consisting of the headerSize, width, height, planes, and bitsPerPixel fields (12 bytes).
///
/// The data to parse.
/// The parsed header.
///
- public static BmpInfoHeader ParseCore(ReadOnlySpan data)
- {
- return new BmpInfoHeader(
+ public static BmpInfoHeader ParseCore(ReadOnlySpan data) => new(
headerSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)),
width: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(4, 2)),
height: BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(6, 2)),
planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(8, 2)),
bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(10, 2)));
- }
///
/// Parses a short variant of the OS22XBITMAPHEADER. It is identical to the BITMAPCOREHEADER, except that the width and height
@@ -296,15 +321,12 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The data to parse.
/// The parsed header.
///
- public static BmpInfoHeader ParseOs22Short(ReadOnlySpan data)
- {
- return new BmpInfoHeader(
+ public static BmpInfoHeader ParseOs22Short(ReadOnlySpan data) => new(
headerSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)),
width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)),
height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)),
planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)),
bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2)));
- }
///
/// Parses the full BMP Version 3 BITMAPINFOHEADER header (40 bytes).
@@ -312,9 +334,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The data to parse.
/// The parsed header.
///
- public static BmpInfoHeader ParseV3(ReadOnlySpan data)
- {
- return new BmpInfoHeader(
+ public static BmpInfoHeader ParseV3(ReadOnlySpan data) => new(
headerSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)),
width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)),
height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)),
@@ -326,7 +346,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp
yPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(28, 4)),
clrUsed: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(32, 4)),
clrImportant: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(36, 4)));
- }
///
/// Special case of the BITMAPINFOHEADER V3 used by adobe where the color bitmasks are part of the info header instead of following it.
@@ -336,9 +355,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// Indicates, if the alpha bitmask is present.
/// The parsed header.
///
- public static BmpInfoHeader ParseAdobeV3(ReadOnlySpan data, bool withAlpha = true)
- {
- return new BmpInfoHeader(
+ public static BmpInfoHeader ParseAdobeV3(ReadOnlySpan data, bool withAlpha = true) => new(
headerSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)),
width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)),
height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)),
@@ -354,7 +371,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp
greenMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(44, 4)),
blueMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(48, 4)),
alphaMask: withAlpha ? BinaryPrimitives.ReadInt32LittleEndian(data.Slice(52, 4)) : 0);
- }
///
/// Parses a OS/2 version 2 bitmap header (64 bytes). Only the first 40 bytes are parsed which are
@@ -413,11 +429,47 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// The data to parse.
/// The parsed header.
///
- public static BmpInfoHeader ParseV4(ReadOnlySpan data)
+ public static BmpInfoHeader ParseV4(ReadOnlySpan data) => new(
+ headerSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(0, 4)),
+ width: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(4, 4)),
+ height: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(8, 4)),
+ planes: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(12, 2)),
+ bitsPerPixel: BinaryPrimitives.ReadInt16LittleEndian(data.Slice(14, 2)),
+ compression: (BmpCompression)BinaryPrimitives.ReadInt32LittleEndian(data.Slice(16, 4)),
+ imageSize: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(20, 4)),
+ xPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(24, 4)),
+ yPelsPerMeter: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(28, 4)),
+ clrUsed: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(32, 4)),
+ clrImportant: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(36, 4)),
+ redMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(40, 4)),
+ greenMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(44, 4)),
+ blueMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(48, 4)),
+ alphaMask: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(52, 4)),
+ csType: (BmpColorSpace)BinaryPrimitives.ReadInt32LittleEndian(data.Slice(56, 4)),
+ redX: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(60, 4)),
+ redY: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(64, 4)),
+ redZ: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(68, 4)),
+ greenX: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(72, 4)),
+ greenY: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(76, 4)),
+ greenZ: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(80, 4)),
+ blueX: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(84, 4)),
+ blueY: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(88, 4)),
+ blueZ: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(92, 4)),
+ gammeRed: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(96, 4)),
+ gammeGreen: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(100, 4)),
+ gammeBlue: BinaryPrimitives.ReadInt32LittleEndian(data.Slice(104, 4)));
+
+ ///
+ /// Parses the full BMP Version 5 BITMAPINFOHEADER header (124 bytes).
+ ///
+ /// The data to parse.
+ /// The parsed header.
+ ///
+ public static BmpInfoHeader ParseV5(ReadOnlySpan data)
{
- if (data.Length < SizeV4)
+ if (data.Length < SizeV5)
{
- throw new ArgumentException(nameof(data), $"Must be {SizeV4} bytes. Was {data.Length} bytes.");
+ throw new ArgumentException(nameof(data), $"Must be {SizeV5} bytes. Was {data.Length} bytes.");
}
return MemoryMarshal.Cast(data)[0];
@@ -448,6 +500,43 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// The buffer to write to.
public void WriteV4Header(Span buffer)
+ {
+ buffer.Clear();
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(0, 4), SizeV4);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(4, 4), this.Width);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(8, 4), this.Height);
+ BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(12, 2), this.Planes);
+ BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(14, 2), this.BitsPerPixel);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(16, 4), (int)this.Compression);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(20, 4), this.ImageSize);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(24, 4), this.XPelsPerMeter);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(28, 4), this.YPelsPerMeter);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(32, 4), this.ClrUsed);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(36, 4), this.ClrImportant);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(40, 4), this.RedMask);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(44, 4), this.GreenMask);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(48, 4), this.BlueMask);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(52, 4), this.AlphaMask);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(56, 4), (int)this.CsType);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(60, 4), this.RedX);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(64, 4), this.RedY);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(68, 4), this.RedZ);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(72, 4), this.GreenX);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(76, 4), this.GreenY);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(80, 4), this.GreenZ);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(84, 4), this.BlueX);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(88, 4), this.BlueY);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(92, 4), this.BlueZ);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(96, 4), this.GammaRed);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(100, 4), this.GammaGreen);
+ BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(104, 4), this.GammaBlue);
+ }
+
+ ///
+ /// Writes a complete Bitmap V5 header to a buffer.
+ ///
+ /// The buffer to write to.
+ public void WriteV5Header(Span buffer)
{
ref BmpInfoHeader dest = ref Unsafe.As(ref MemoryMarshal.GetReference(buffer));
diff --git a/src/ImageSharp/Formats/Bmp/BmpInfoHeaderType.cs b/src/ImageSharp/Formats/Bmp/BmpInfoHeaderType.cs
index 86bfdf9bf3..34b063ae42 100644
--- a/src/ImageSharp/Formats/Bmp/BmpInfoHeaderType.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpInfoHeaderType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpMetadata.cs b/src/ImageSharp/Formats/Bmp/BmpMetadata.cs
index b7b668a7ab..4a0725a7ae 100644
--- a/src/ImageSharp/Formats/Bmp/BmpMetadata.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/BmpRenderingIntent.cs b/src/ImageSharp/Formats/Bmp/BmpRenderingIntent.cs
new file mode 100644
index 0000000000..2000a27941
--- /dev/null
+++ b/src/ImageSharp/Formats/Bmp/BmpRenderingIntent.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+// ReSharper disable InconsistentNaming
+namespace SixLabors.ImageSharp.Formats.Bmp
+{
+ ///
+ /// Enum for the different rendering intent's.
+ ///
+ internal enum BmpRenderingIntent
+ {
+ ///
+ /// Invalid default value.
+ ///
+ Invalid = 0,
+
+ ///
+ /// Maintains saturation. Used for business charts and other situations in which undithered colors are required.
+ ///
+ LCS_GM_BUSINESS = 1,
+
+ ///
+ /// Maintains colorimetric match. Used for graphic designs and named colors.
+ ///
+ LCS_GM_GRAPHICS = 2,
+
+ ///
+ /// Maintains contrast. Used for photographs and natural images.
+ ///
+ LCS_GM_IMAGES = 4,
+
+ ///
+ /// Maintains the white point. Matches the colors to their nearest color in the destination gamut.
+ ///
+ LCS_GM_ABS_COLORIMETRIC = 8,
+ }
+}
diff --git a/src/ImageSharp/Formats/Bmp/BmpThrowHelper.cs b/src/ImageSharp/Formats/Bmp/BmpThrowHelper.cs
index 3d577d278f..5fa760b8ee 100644
--- a/src/ImageSharp/Formats/Bmp/BmpThrowHelper.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs
index ff88d15a31..1283d0ae16 100644
--- a/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Bmp/IBmpDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
index 30aa70452e..9c035119d8 100644
--- a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
diff --git a/src/ImageSharp/Formats/Bmp/MetadataExtensions.cs b/src/ImageSharp/Formats/Bmp/MetadataExtensions.cs
index a6f212e2e7..5c7f9c2d45 100644
--- a/src/ImageSharp/Formats/Bmp/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Bmp/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Bmp/RleSkippedPixelHandling.cs b/src/ImageSharp/Formats/Bmp/RleSkippedPixelHandling.cs
index ce113dce72..4e23947c1a 100644
--- a/src/ImageSharp/Formats/Bmp/RleSkippedPixelHandling.cs
+++ b/src/ImageSharp/Formats/Bmp/RleSkippedPixelHandling.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Bmp
{
diff --git a/src/ImageSharp/Formats/Gif/GifColorTableMode.cs b/src/ImageSharp/Formats/Gif/GifColorTableMode.cs
index b8569a321f..a33dc1707e 100644
--- a/src/ImageSharp/Formats/Gif/GifColorTableMode.cs
+++ b/src/ImageSharp/Formats/Gif/GifColorTableMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs b/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs
index 8f846f9d5d..108026ffec 100644
--- a/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Gif/GifConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifConstants.cs b/src/ImageSharp/Formats/Gif/GifConstants.cs
index 1179b67b1e..4aa18bacb1 100644
--- a/src/ImageSharp/Formats/Gif/GifConstants.cs
+++ b/src/ImageSharp/Formats/Gif/GifConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs
index 6d6cfc0792..666c3b92c1 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index d17e89cd45..25354f6f33 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Gets the dimensions of the image.
///
- public Size Dimensions => new Size(this.imageDescriptor.Width, this.imageDescriptor.Height);
+ public Size Dimensions => new(this.imageDescriptor.Width, this.imageDescriptor.Height);
private MemoryAllocator MemoryAllocator => this.Configuration.MemoryAllocator;
diff --git a/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs b/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
index 2211dfe4b9..d5823e44ff 100644
--- a/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
+++ b/src/ImageSharp/Formats/Gif/GifDisposalMethod.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs
index 116ee3daeb..937e65db94 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index da5b1cb236..bb45c8364b 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Gif/GifFormat.cs b/src/ImageSharp/Formats/Gif/GifFormat.cs
index 459f0068be..aa05d93cc4 100644
--- a/src/ImageSharp/Formats/Gif/GifFormat.cs
+++ b/src/ImageSharp/Formats/Gif/GifFormat.cs
@@ -1,5 +1,5 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Gets the current instance.
///
- public static GifFormat Instance { get; } = new GifFormat();
+ public static GifFormat Instance { get; } = new();
///
public string Name => "GIF";
@@ -32,9 +32,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
public IEnumerable FileExtensions => GifConstants.FileExtensions;
///
- public GifMetadata CreateDefaultFormatMetadata() => new GifMetadata();
+ public GifMetadata CreateDefaultFormatMetadata() => new();
///
- public GifFrameMetadata CreateDefaultFormatFrameMetadata() => new GifFrameMetadata();
+ public GifFrameMetadata CreateDefaultFormatFrameMetadata() => new();
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
index c254a7650d..2ebf73d7e6 100644
--- a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
+++ b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif
{
diff --git a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
index 736b9246dc..4f006b799f 100644
--- a/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Gif/GifMetadata.cs b/src/ImageSharp/Formats/Gif/GifMetadata.cs
index 686288a980..de09347bef 100644
--- a/src/ImageSharp/Formats/Gif/GifMetadata.cs
+++ b/src/ImageSharp/Formats/Gif/GifMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Gif/GifThrowHelper.cs b/src/ImageSharp/Formats/Gif/GifThrowHelper.cs
index b85bb139ad..88fb264923 100644
--- a/src/ImageSharp/Formats/Gif/GifThrowHelper.cs
+++ b/src/ImageSharp/Formats/Gif/GifThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
index 56bb6d6519..74068e1624 100644
--- a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
index 909d1c3a72..dfc1e69c79 100644
--- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
index 2a07200016..893fde55e6 100644
--- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
index c52e34f963..1146bcf911 100644
--- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Gif/MetadataExtensions.cs b/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
index 2e8dda5c05..64bce03a26 100644
--- a/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Gif/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
index 8476336942..7dcf38f586 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
index 1eaebe11dd..07e0f6f0ce 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifImageDescriptor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
index e3bc2e883c..4b2dad895a 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
index c9e8033dbd..d9ee93883d 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs b/src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs
index 8c396e7fb3..d3a621e7be 100644
--- a/src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs b/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
index d2783fc48d..59cef0d2e6 100644
--- a/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
+++ b/src/ImageSharp/Formats/Gif/Sections/IGifExtension.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs
index db7f64ee26..82c7804d57 100644
--- a/src/ImageSharp/Formats/IImageDecoder.cs
+++ b/src/ImageSharp/Formats/IImageDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/IImageDecoderInternals.cs b/src/ImageSharp/Formats/IImageDecoderInternals.cs
index e190f7adda..db3d71b894 100644
--- a/src/ImageSharp/Formats/IImageDecoderInternals.cs
+++ b/src/ImageSharp/Formats/IImageDecoderInternals.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Threading;
diff --git a/src/ImageSharp/Formats/IImageEncoder.cs b/src/ImageSharp/Formats/IImageEncoder.cs
index e5a1b1c839..40831ed7c3 100644
--- a/src/ImageSharp/Formats/IImageEncoder.cs
+++ b/src/ImageSharp/Formats/IImageEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/IImageEncoderInternals.cs b/src/ImageSharp/Formats/IImageEncoderInternals.cs
index d44ac45f27..824a08f5a7 100644
--- a/src/ImageSharp/Formats/IImageEncoderInternals.cs
+++ b/src/ImageSharp/Formats/IImageEncoderInternals.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/IImageFormat.cs b/src/ImageSharp/Formats/IImageFormat.cs
index 812984ba8e..c853ca413a 100644
--- a/src/ImageSharp/Formats/IImageFormat.cs
+++ b/src/ImageSharp/Formats/IImageFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/IImageFormatDetector.cs b/src/ImageSharp/Formats/IImageFormatDetector.cs
index 96c3a49afe..4175cf0ece 100644
--- a/src/ImageSharp/Formats/IImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/IImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/IImageInfoDetector.cs b/src/ImageSharp/Formats/IImageInfoDetector.cs
index c6377edd0b..2d30af5ceb 100644
--- a/src/ImageSharp/Formats/IImageInfoDetector.cs
+++ b/src/ImageSharp/Formats/IImageInfoDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/ImageDecoderUtilities.cs b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
index 71ecda8938..b6cefd2c89 100644
--- a/src/ImageSharp/Formats/ImageDecoderUtilities.cs
+++ b/src/ImageSharp/Formats/ImageDecoderUtilities.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/ImageEncoderUtilities.cs b/src/ImageSharp/Formats/ImageEncoderUtilities.cs
index 896fffa6fc..d9fb701501 100644
--- a/src/ImageSharp/Formats/ImageEncoderUtilities.cs
+++ b/src/ImageSharp/Formats/ImageEncoderUtilities.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.cs b/src/ImageSharp/Formats/ImageExtensions.Save.cs
index 84f9d69b7e..91f44e01d5 100644
--- a/src/ImageSharp/Formats/ImageExtensions.Save.cs
+++ b/src/ImageSharp/Formats/ImageExtensions.Save.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
//
using System.IO;
diff --git a/src/ImageSharp/Formats/ImageExtensions.Save.tt b/src/ImageSharp/Formats/ImageExtensions.Save.tt
index ae7648522f..2a756b4837 100644
--- a/src/ImageSharp/Formats/ImageExtensions.Save.tt
+++ b/src/ImageSharp/Formats/ImageExtensions.Save.tt
@@ -2,7 +2,7 @@
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
//
using System.IO;
diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs
index f3fde403da..9f3f0d47fe 100644
--- a/src/ImageSharp/Formats/ImageFormatManager.cs
+++ b/src/ImageSharp/Formats/ImageFormatManager.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Concurrent;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.Intrinsic.cs
index 002d382dc6..8eba118fda 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.Intrinsic.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.Intrinsic.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
index e3b15b7535..040f7092f7 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
index 181aa6d376..4c40659261 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
index 8897efbe00..7d5a347a12 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt
@@ -1,6 +1,6 @@
<#
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
@@ -9,7 +9,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs
index 0971ccdca0..2a03f911b9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System;
@@ -35,8 +35,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
[FieldOffset(224)]
public Vector256 V7;
- private static readonly Vector256 MultiplyIntoInt16ShuffleMask = Vector256.Create(0, 1, 4, 5, 2, 3, 6, 7);
-
private static unsafe void MultiplyIntoInt16_Avx2(ref Block8x8F a, ref Block8x8F b, ref Block8x8 dest)
{
DebugGuard.IsTrue(Avx2.IsSupported, "Avx2 support is required to run this operation!");
@@ -45,6 +43,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
ref Vector256 bBase = ref b.V0;
ref Vector256 destRef = ref dest.V01;
+ Vector256 multiplyIntoInt16ShuffleMask = Vector256.Create(0, 1, 4, 5, 2, 3, 6, 7);
for (nint i = 0; i < 8; i += 2)
{
@@ -52,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
Vector256 row1 = Avx.ConvertToVector256Int32(Avx.Multiply(Unsafe.Add(ref aBase, i + 1), Unsafe.Add(ref bBase, i + 1)));
Vector256 row = Avx2.PackSignedSaturate(row0, row1);
- row = Avx2.PermuteVar8x32(row.AsInt32(), MultiplyIntoInt16ShuffleMask).AsInt16();
+ row = Avx2.PermuteVar8x32(row.AsInt32(), multiplyIntoInt16ShuffleMask).AsInt16();
Unsafe.Add(ref destRef, (IntPtr)((uint)i / 2)) = row;
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
index 0190fc7454..d2f3e9664b 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
index aa57162d3c..5fd97e3684 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
index 251e970154..ba36733804 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs
index 429b8677b6..6cd04c2fc2 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
+using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
@@ -25,13 +26,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
- ///
- /// Gets a value indicating whether this converter is supported on current hardware.
- ///
- public static bool IsSupported => Avx.IsSupported;
+ public sealed override bool IsAvailable => Avx.IsSupported;
- ///
- public override bool IsAvailable => IsSupported;
+ public sealed override int ElementsPerBatch => Vector256.Count;
}
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
index 86b15e888e..db2159ba05 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
@@ -34,6 +34,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
///
public abstract bool IsAvailable { get; }
+ ///
+ /// Gets a value indicating how many pixels are processed in a single batch.
+ ///
+ ///
+ /// This generally should be equal to register size,
+ /// e.g. 1 for scalar implementation, 8 for AVX implementation and so on.
+ ///
+ public abstract int ElementsPerBatch { get; }
+
///
/// Gets the of this converter.
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs
index d962f434f0..9de8e16a27 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
@@ -16,8 +16,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
- ///
- public override bool IsAvailable => true;
+ public sealed override bool IsAvailable => true;
+
+ public sealed override int ElementsPerBatch => 1;
}
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ComponentType.cs b/src/ImageSharp/Formats/Jpeg/Components/ComponentType.cs
index ff3c0539c6..0c0b0e7924 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ComponentType.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ComponentType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
index b41d52aa40..acf43092c6 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingComponent.cs
index a2736900f7..043df57069 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingTable.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingTable.cs
index 6055f300d5..4c02852d53 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingTable.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticDecodingTable.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
index 15fdb3dc4b..592b4bbaea 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
@@ -326,11 +326,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
if (this.scanComponentCount != 1)
{
+ this.spectralConverter.PrepareForDecoding();
this.ParseBaselineDataInterleaved();
this.spectralConverter.CommitConversion();
}
else if (this.frame.ComponentCount == 1)
{
+ this.spectralConverter.PrepareForDecoding();
this.ParseBaselineDataSingleComponent();
this.spectralConverter.CommitConversion();
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs
index c84831b3aa..251c1d1c3f 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticStatistics.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs
new file mode 100644
index 0000000000..87e85686ca
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/ComponentProcessor.cs
@@ -0,0 +1,65 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using SixLabors.ImageSharp.Memory;
+
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
+{
+ ///
+ /// Base class for processing component spectral data and converting it to raw color data.
+ ///
+ internal abstract class ComponentProcessor : IDisposable
+ {
+ public ComponentProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, Size postProcessorBufferSize, IJpegComponent component, int blockSize)
+ {
+ this.Frame = frame;
+ this.Component = component;
+
+ this.BlockAreaSize = component.SubSamplingDivisors * blockSize;
+ this.ColorBuffer = memoryAllocator.Allocate2DOveraligned(
+ postProcessorBufferSize.Width,
+ postProcessorBufferSize.Height,
+ this.BlockAreaSize.Height);
+ }
+
+ protected JpegFrame Frame { get; }
+
+ protected IJpegComponent Component { get; }
+
+ protected Buffer2D ColorBuffer { get; }
+
+ protected Size BlockAreaSize { get; }
+
+ ///
+ /// Converts spectral data to color data accessible via .
+ ///
+ /// Spectral row index to convert.
+ public abstract void CopyBlocksToColorBuffer(int row);
+
+ ///
+ /// Clears spectral buffers.
+ ///
+ ///
+ /// Should only be called during baseline interleaved decoding.
+ ///
+ public void ClearSpectralBuffers()
+ {
+ Buffer2D spectralBlocks = this.Component.SpectralBlocks;
+ for (int i = 0; i < spectralBlocks.Height; i++)
+ {
+ spectralBlocks.DangerousGetRowSpan(i).Clear();
+ }
+ }
+
+ ///
+ /// Gets converted color buffer row.
+ ///
+ /// Row index.
+ /// Color buffer row.
+ public Span GetColorBufferRowSpan(int row) =>
+ this.ColorBuffer.DangerousGetRowSpan(row);
+
+ public void Dispose() => this.ColorBuffer.Dispose();
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs
new file mode 100644
index 0000000000..80cc689e3b
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DirectComponentProcessor.cs
@@ -0,0 +1,73 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using SixLabors.ImageSharp.Memory;
+
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
+{
+ ///
+ /// Processes component spectral data and converts it to color data in 1-to-1 scale.
+ ///
+ internal sealed class DirectComponentProcessor : ComponentProcessor
+ {
+ private Block8x8F dequantizationTable;
+
+ public DirectComponentProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
+ : base(memoryAllocator, frame, postProcessorBufferSize, component, blockSize: 8)
+ {
+ this.dequantizationTable = rawJpeg.QuantizationTables[component.QuantizationTableIndex];
+ FloatingPointDCT.AdjustToIDCT(ref this.dequantizationTable);
+ }
+
+ public override void CopyBlocksToColorBuffer(int spectralStep)
+ {
+ Buffer2D spectralBuffer = this.Component.SpectralBlocks;
+
+ float maximumValue = this.Frame.MaxColorChannelValue;
+
+ int destAreaStride = this.ColorBuffer.Width;
+
+ int blocksRowsPerStep = this.Component.SamplingFactors.Height;
+
+ int yBlockStart = spectralStep * blocksRowsPerStep;
+
+ Size subSamplingDivisors = this.Component.SubSamplingDivisors;
+
+ Block8x8F workspaceBlock = default;
+
+ for (int y = 0; y < blocksRowsPerStep; y++)
+ {
+ int yBuffer = y * this.BlockAreaSize.Height;
+
+ Span colorBufferRow = this.ColorBuffer.DangerousGetRowSpan(yBuffer);
+ Span blockRow = spectralBuffer.DangerousGetRowSpan(yBlockStart + y);
+
+ for (int xBlock = 0; xBlock < spectralBuffer.Width; xBlock++)
+ {
+ // Integer to float
+ workspaceBlock.LoadFrom(ref blockRow[xBlock]);
+
+ // Dequantize
+ workspaceBlock.MultiplyInPlace(ref this.dequantizationTable);
+
+ // Convert from spectral to color
+ FloatingPointDCT.TransformIDCT(ref workspaceBlock);
+
+ // To conform better to libjpeg we actually NEED TO loose precision here.
+ // This is because they store blocks as Int16 between all the operations.
+ // To be "more accurate", we need to emulate this by rounding!
+ workspaceBlock.NormalizeColorsAndRoundInPlace(maximumValue);
+
+ // Write to color buffer acording to sampling factors
+ int xColorBufferStart = xBlock * this.BlockAreaSize.Width;
+ workspaceBlock.ScaledCopyTo(
+ ref colorBufferRow[xColorBufferStart],
+ destAreaStride,
+ subSamplingDivisors.Width,
+ subSamplingDivisors.Height);
+ }
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs
new file mode 100644
index 0000000000..801b2a3fbd
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor2.cs
@@ -0,0 +1,102 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using System.Runtime.CompilerServices;
+using SixLabors.ImageSharp.Memory;
+
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
+{
+ ///
+ /// Processes component spectral data and converts it to color data in 2-to-1 scale.
+ ///
+ internal sealed class DownScalingComponentProcessor2 : ComponentProcessor
+ {
+ private Block8x8F dequantizationTable;
+
+ public DownScalingComponentProcessor2(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
+ : base(memoryAllocator, frame, postProcessorBufferSize, component, 4)
+ {
+ this.dequantizationTable = rawJpeg.QuantizationTables[component.QuantizationTableIndex];
+ ScaledFloatingPointDCT.AdjustToIDCT(ref this.dequantizationTable);
+ }
+
+ public override void CopyBlocksToColorBuffer(int spectralStep)
+ {
+ Buffer2D spectralBuffer = this.Component.SpectralBlocks;
+
+ float maximumValue = this.Frame.MaxColorChannelValue;
+ float normalizationValue = MathF.Ceiling(maximumValue / 2);
+
+ int destAreaStride = this.ColorBuffer.Width;
+
+ int blocksRowsPerStep = this.Component.SamplingFactors.Height;
+ Size subSamplingDivisors = this.Component.SubSamplingDivisors;
+
+ Block8x8F workspaceBlock = default;
+
+ int yBlockStart = spectralStep * blocksRowsPerStep;
+
+ for (int y = 0; y < blocksRowsPerStep; y++)
+ {
+ int yBuffer = y * this.BlockAreaSize.Height;
+
+ Span colorBufferRow = this.ColorBuffer.DangerousGetRowSpan(yBuffer);
+ Span blockRow = spectralBuffer.DangerousGetRowSpan(yBlockStart + y);
+
+ for (int xBlock = 0; xBlock < spectralBuffer.Width; xBlock++)
+ {
+ // Integer to float
+ workspaceBlock.LoadFrom(ref blockRow[xBlock]);
+
+ // IDCT/Normalization/Range
+ ScaledFloatingPointDCT.TransformIDCT_4x4(ref workspaceBlock, ref this.dequantizationTable, normalizationValue, maximumValue);
+
+ // Save to the intermediate buffer
+ int xColorBufferStart = xBlock * this.BlockAreaSize.Width;
+ ScaledCopyTo(
+ ref workspaceBlock,
+ ref colorBufferRow[xColorBufferStart],
+ destAreaStride,
+ subSamplingDivisors.Width,
+ subSamplingDivisors.Height);
+ }
+ }
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void ScaledCopyTo(ref Block8x8F block, ref float destRef, int destStrideWidth, int horizontalScale, int verticalScale)
+ {
+ // TODO: Optimize: implement all cases with scale-specific, loopless code!
+ CopyArbitraryScale(ref block, ref destRef, destStrideWidth, horizontalScale, verticalScale);
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale)
+ {
+ for (int y = 0; y < 4; y++)
+ {
+ int yy = y * verticalScale;
+ int y8 = y * 8;
+
+ for (int x = 0; x < 4; x++)
+ {
+ int xx = x * horizontalScale;
+
+ float value = block[y8 + x];
+
+ for (int i = 0; i < verticalScale; i++)
+ {
+ int baseIdx = ((yy + i) * areaStride) + xx;
+
+ for (int j = 0; j < horizontalScale; j++)
+ {
+ // area[xx + j, yy + i] = value;
+ Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs
new file mode 100644
index 0000000000..1c63abc932
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor4.cs
@@ -0,0 +1,102 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using System.Runtime.CompilerServices;
+using SixLabors.ImageSharp.Memory;
+
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
+{
+ ///
+ /// Processes component spectral data and converts it to color data in 4-to-1 scale.
+ ///
+ internal sealed class DownScalingComponentProcessor4 : ComponentProcessor
+ {
+ private Block8x8F dequantizationTable;
+
+ public DownScalingComponentProcessor4(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
+ : base(memoryAllocator, frame, postProcessorBufferSize, component, 2)
+ {
+ this.dequantizationTable = rawJpeg.QuantizationTables[component.QuantizationTableIndex];
+ ScaledFloatingPointDCT.AdjustToIDCT(ref this.dequantizationTable);
+ }
+
+ public override void CopyBlocksToColorBuffer(int spectralStep)
+ {
+ Buffer2D spectralBuffer = this.Component.SpectralBlocks;
+
+ float maximumValue = this.Frame.MaxColorChannelValue;
+ float normalizationValue = MathF.Ceiling(maximumValue / 2);
+
+ int destAreaStride = this.ColorBuffer.Width;
+
+ int blocksRowsPerStep = this.Component.SamplingFactors.Height;
+ Size subSamplingDivisors = this.Component.SubSamplingDivisors;
+
+ Block8x8F workspaceBlock = default;
+
+ int yBlockStart = spectralStep * blocksRowsPerStep;
+
+ for (int y = 0; y < blocksRowsPerStep; y++)
+ {
+ int yBuffer = y * this.BlockAreaSize.Height;
+
+ Span colorBufferRow = this.ColorBuffer.DangerousGetRowSpan(yBuffer);
+ Span blockRow = spectralBuffer.DangerousGetRowSpan(yBlockStart + y);
+
+ for (int xBlock = 0; xBlock < spectralBuffer.Width; xBlock++)
+ {
+ // Integer to float
+ workspaceBlock.LoadFrom(ref blockRow[xBlock]);
+
+ // IDCT/Normalization/Range
+ ScaledFloatingPointDCT.TransformIDCT_2x2(ref workspaceBlock, ref this.dequantizationTable, normalizationValue, maximumValue);
+
+ // Save to the intermediate buffer
+ int xColorBufferStart = xBlock * this.BlockAreaSize.Width;
+ ScaledCopyTo(
+ ref workspaceBlock,
+ ref colorBufferRow[xColorBufferStart],
+ destAreaStride,
+ subSamplingDivisors.Width,
+ subSamplingDivisors.Height);
+ }
+ }
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void ScaledCopyTo(ref Block8x8F block, ref float destRef, int destStrideWidth, int horizontalScale, int verticalScale)
+ {
+ // TODO: Optimize: implement all cases with scale-specific, loopless code!
+ CopyArbitraryScale(ref block, ref destRef, destStrideWidth, horizontalScale, verticalScale);
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ static void CopyArbitraryScale(ref Block8x8F block, ref float areaOrigin, int areaStride, int horizontalScale, int verticalScale)
+ {
+ for (int y = 0; y < 2; y++)
+ {
+ int yy = y * verticalScale;
+ int y8 = y * 8;
+
+ for (int x = 0; x < 2; x++)
+ {
+ int xx = x * horizontalScale;
+
+ float value = block[y8 + x];
+
+ for (int i = 0; i < verticalScale; i++)
+ {
+ int baseIdx = ((yy + i) * areaStride) + xx;
+
+ for (int j = 0; j < horizontalScale; j++)
+ {
+ // area[xx + j, yy + i] = value;
+ Unsafe.Add(ref areaOrigin, (nint)(uint)(baseIdx + j)) = value;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs
new file mode 100644
index 0000000000..03f0de7411
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ComponentProcessors/DownScalingComponentProcessor8.cs
@@ -0,0 +1,88 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using System.Runtime.CompilerServices;
+using SixLabors.ImageSharp.Memory;
+
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
+{
+ ///
+ /// Processes component spectral data and converts it to color data in 8-to-1 scale.
+ ///
+ internal sealed class DownScalingComponentProcessor8 : ComponentProcessor
+ {
+ private readonly float dcDequantizatizer;
+
+ public DownScalingComponentProcessor8(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
+ : base(memoryAllocator, frame, postProcessorBufferSize, component, 1)
+ => this.dcDequantizatizer = 0.125f * rawJpeg.QuantizationTables[component.QuantizationTableIndex][0];
+
+ public override void CopyBlocksToColorBuffer(int spectralStep)
+ {
+ Buffer2D spectralBuffer = this.Component.SpectralBlocks;
+
+ float maximumValue = this.Frame.MaxColorChannelValue;
+ float normalizationValue = MathF.Ceiling(maximumValue / 2);
+
+ int destAreaStride = this.ColorBuffer.Width;
+
+ int blocksRowsPerStep = this.Component.SamplingFactors.Height;
+ Size subSamplingDivisors = this.Component.SubSamplingDivisors;
+
+ int yBlockStart = spectralStep * blocksRowsPerStep;
+
+ for (int y = 0; y < blocksRowsPerStep; y++)
+ {
+ int yBuffer = y * this.BlockAreaSize.Height;
+
+ Span colorBufferRow = this.ColorBuffer.DangerousGetRowSpan(yBuffer);
+ Span blockRow = spectralBuffer.DangerousGetRowSpan(yBlockStart + y);
+
+ for (int xBlock = 0; xBlock < spectralBuffer.Width; xBlock++)
+ {
+ float dc = ScaledFloatingPointDCT.TransformIDCT_1x1(blockRow[xBlock][0], this.dcDequantizatizer, normalizationValue, maximumValue);
+
+ // Save to the intermediate buffer
+ int xColorBufferStart = xBlock * this.BlockAreaSize.Width;
+ ScaledCopyTo(
+ dc,
+ ref colorBufferRow[xColorBufferStart],
+ destAreaStride,
+ subSamplingDivisors.Width,
+ subSamplingDivisors.Height);
+ }
+ }
+ }
+
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void ScaledCopyTo(float value, ref float destRef, int destStrideWidth, int horizontalScale, int verticalScale)
+ {
+ if (horizontalScale == 1 && verticalScale == 1)
+ {
+ destRef = value;
+ return;
+ }
+
+ if (horizontalScale == 2 && verticalScale == 2)
+ {
+ destRef = value;
+ Unsafe.Add(ref destRef, 1) = value;
+ Unsafe.Add(ref destRef, 0 + (nint)(uint)destStrideWidth) = value;
+ Unsafe.Add(ref destRef, 1 + (nint)(uint)destStrideWidth) = value;
+ return;
+ }
+
+ // TODO: Optimize: implement all cases with scale-specific, loopless code!
+ for (int y = 0; y < verticalScale; y++)
+ {
+ for (int x = 0; x < horizontalScale; x++)
+ {
+ Unsafe.Add(ref destRef, (nint)(uint)x) = value;
+ }
+
+ destRef = ref Unsafe.Add(ref destRef, (nint)(uint)destStrideWidth);
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
index 308c52dbac..8013e51f8f 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
@@ -109,10 +109,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
// The successive approximation low bit end.
public int SuccessiveLow { get; set; }
- ///
- /// Decodes the entropy coded data.
- ///
- /// Component count in the current scan.
+ ///
public void ParseEntropyCodedData(int scanComponentCount)
{
this.cancellationToken.ThrowIfCancellationRequested();
@@ -152,11 +149,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
if (this.scanComponentCount != 1)
{
+ this.spectralConverter.PrepareForDecoding();
this.ParseBaselineDataInterleaved();
this.spectralConverter.CommitConversion();
}
else if (this.frame.ComponentCount == 1)
{
+ this.spectralConverter.PrepareForDecoding();
this.ParseBaselineDataSingleComponent();
this.spectralConverter.CommitConversion();
}
@@ -269,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private void ParseBaselineDataSingleComponent()
{
- var component = this.frame.Components[0] as JpegComponent;
+ JpegComponent component = this.frame.Components[0];
int mcuLines = this.frame.McusPerColumn;
int w = component.WidthInBlocks;
int h = component.SamplingFactors.Height;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
index 79713388b2..5ef9f760c9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
index adab8c2ec3..2e4215325d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegScanDecoder.cs
index 73ca9f08b2..e270198b7c 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegScanDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IJpegScanDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
index dd7ca4e7ff..cbbb44ffbc 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/IRawJpegData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
index a95e6c16c2..89d3d412d0 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBitReader.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBitReader.cs
index 84013319e1..b5e9009ec9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBitReader.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBitReader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.IO;
@@ -155,12 +155,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
c = this.ReadStream();
}
+ // Found a marker
// We accept multiple FF bytes followed by a 0 as meaning a single FF data byte.
- // This data pattern is not valid according to the standard.
+ // even though it's considered 'invalid' according to the specs.
if (c != 0)
{
- this.Marker = (byte)c;
+ // It's a trick so we won't read past actual marker
this.badData = true;
+ this.Marker = (byte)c;
this.MarkerPosition = this.stream.Position - 2;
}
}
@@ -199,7 +201,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
if (b != 0)
{
this.Marker = (byte)b;
- this.badData = true;
this.MarkerPosition = this.stream.Position - 2;
return true;
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
index 5b0e877853..82f6be7548 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Memory;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
deleted file mode 100644
index 6173c4fbf8..0000000000
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using SixLabors.ImageSharp.Memory;
-
-namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
-{
- ///
- /// Encapsulates spectral data to rgba32 processing for one component.
- ///
- internal class JpegComponentPostProcessor : IDisposable
- {
- ///
- /// The size of the area in corresponding to one 8x8 Jpeg block
- ///
- private readonly Size blockAreaSize;
-
- ///
- /// Jpeg frame instance containing required decoding metadata.
- ///
- private readonly JpegFrame frame;
-
- ///
- /// Gets the maximal number of block rows being processed in one step.
- ///
- private readonly int blockRowsPerStep;
-
- ///
- /// Gets the component containing decoding meta information.
- ///
- private readonly IJpegComponent component;
-
- ///
- /// Gets the instance containing decoding meta information.
- ///
- private readonly IRawJpegData rawJpeg;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
- {
- this.frame = frame;
-
- this.component = component;
- this.rawJpeg = rawJpeg;
- this.blockAreaSize = this.component.SubSamplingDivisors * 8;
- this.ColorBuffer = memoryAllocator.Allocate2DOveraligned(
- postProcessorBufferSize.Width,
- postProcessorBufferSize.Height,
- this.blockAreaSize.Height);
-
- this.blockRowsPerStep = postProcessorBufferSize.Height / 8 / this.component.SubSamplingDivisors.Height;
- }
-
- ///
- /// Gets the temporary working buffer of color values.
- ///
- public Buffer2D ColorBuffer { get; }
-
- ///
- public void Dispose() => this.ColorBuffer.Dispose();
-
- ///
- /// Convert raw spectral DCT data to color data and copy it to the color buffer .
- ///
- public void CopyBlocksToColorBuffer(int spectralStep)
- {
- Buffer2D spectralBuffer = this.component.SpectralBlocks;
-
- float maximumValue = this.frame.MaxColorChannelValue;
-
- int destAreaStride = this.ColorBuffer.Width;
-
- int yBlockStart = spectralStep * this.blockRowsPerStep;
-
- Size subSamplingDivisors = this.component.SubSamplingDivisors;
-
- Block8x8F dequantTable = this.rawJpeg.QuantizationTables[this.component.QuantizationTableIndex];
- Block8x8F workspaceBlock = default;
-
- for (int y = 0; y < this.blockRowsPerStep; y++)
- {
- int yBuffer = y * this.blockAreaSize.Height;
-
- Span colorBufferRow = this.ColorBuffer.DangerousGetRowSpan(yBuffer);
- Span blockRow = spectralBuffer.DangerousGetRowSpan(yBlockStart + y);
-
- for (int xBlock = 0; xBlock < spectralBuffer.Width; xBlock++)
- {
- // Integer to float
- workspaceBlock.LoadFrom(ref blockRow[xBlock]);
-
- // Dequantize
- workspaceBlock.MultiplyInPlace(ref dequantTable);
-
- // Convert from spectral to color
- FastFloatingPointDCT.TransformIDCT(ref workspaceBlock);
-
- // To conform better to libjpeg we actually NEED TO loose precision here.
- // This is because they store blocks as Int16 between all the operations.
- // To be "more accurate", we need to emulate this by rounding!
- workspaceBlock.NormalizeColorsAndRoundInPlace(maximumValue);
-
- // Write to color buffer according to sampling factors
- int xColorBufferStart = xBlock * this.blockAreaSize.Width;
- workspaceBlock.ScaledCopyTo(
- ref colorBufferRow[xColorBufferStart],
- destAreaStride,
- subSamplingDivisors.Width,
- subSamplingDivisors.Height);
- }
- }
- }
-
- public void ClearSpectralBuffers()
- {
- Buffer2D spectralBlocks = this.component.SpectralBlocks;
- for (int i = 0; i < spectralBlocks.Height; i++)
- {
- spectralBlocks.DangerousGetRowSpan(i).Clear();
- }
- }
-
- public Span GetColorBufferRowSpan(int row) =>
- this.ColorBuffer.DangerousGetRowSpan(row);
- }
-}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
index 8115437649..f3ceb3584a 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFileMarker.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
index 200096e193..95fe6ee58d 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
@@ -139,8 +139,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
- public void AllocateComponents(bool fullScan)
+ public void AllocateComponents()
{
+ bool fullScan = this.Progressive || this.MultiScan;
for (int i = 0; i < this.ComponentCount; i++)
{
IJpegComponent component = this.Components[i];
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
index b41c949b26..9f1d4d91ff 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
index 34900b1c37..be59e90fab 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
@@ -8,6 +8,21 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
internal abstract class SpectralConverter
{
+ ///
+ /// Supported scaled spectral block sizes for scaled IDCT decoding.
+ ///
+ private static readonly int[] ScaledBlockSizes = new int[]
+ {
+ // 8 => 1, 1/8 of the original size
+ 1,
+
+ // 8 => 2, 1/4 of the original size
+ 2,
+
+ // 8 => 4, 1/2 of the original size
+ 4,
+ };
+
///
/// Gets a value indicating whether this converter has converted spectral
/// data of the current image or not.
@@ -18,12 +33,19 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// Injects jpeg image decoding metadata.
///
///
- /// This is guaranteed to be called only once at SOF marker by .
+ /// This should be called exactly once during SOF (Start Of Frame) marker.
///
- /// instance containing decoder-specific parameters.
- /// instance containing decoder-specific parameters.
+ /// Instance containing decoder-specific parameters.
+ /// Instance containing decoder-specific parameters.
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
+ ///
+ /// Initializes this spectral decoder instance for decoding.
+ /// This should be called exactly once after all markers which can alter
+ /// spectral decoding parameters.
+ ///
+ public abstract void PrepareForDecoding();
+
///
/// Converts single spectral jpeg stride to color stride in baseline
/// decoding mode.
@@ -56,5 +78,48 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// The raw JPEG data.
/// The color converter.
protected virtual JpegColorConverterBase GetColorConverter(JpegFrame frame, IRawJpegData jpegData) => JpegColorConverterBase.GetConverter(jpegData.ColorSpace, frame.Precision);
+
+ ///
+ /// Calculates image size with optional scaling.
+ ///
+ ///
+ /// Does not apply scalling if is null.
+ ///
+ /// Size of the image.
+ /// Target size of the image.
+ /// Spectral block size, equals to 8 if scaling is not applied.
+ /// Resulting image size, equals to if scaling is not applied.
+ public static Size CalculateResultingImageSize(Size size, Size? targetSize, out int blockPixelSize)
+ {
+ const int blockNativePixelSize = 8;
+
+ blockPixelSize = blockNativePixelSize;
+ if (targetSize != null)
+ {
+ Size tSize = targetSize.Value;
+
+ int fullBlocksWidth = (int)((uint)size.Width / blockNativePixelSize);
+ int fullBlocksHeight = (int)((uint)size.Height / blockNativePixelSize);
+
+ // & (blockNativePixelSize - 1) is Numerics.Modulo8(), basically
+ int blockWidthRemainder = size.Width & (blockNativePixelSize - 1);
+ int blockHeightRemainder = size.Height & (blockNativePixelSize - 1);
+
+ for (int i = 0; i < ScaledBlockSizes.Length; i++)
+ {
+ int blockSize = ScaledBlockSizes[i];
+ int scaledWidth = (fullBlocksWidth * blockSize) + (int)Numerics.DivideCeil((uint)(blockWidthRemainder * blockSize), blockNativePixelSize);
+ int scaledHeight = (fullBlocksHeight * blockSize) + (int)Numerics.DivideCeil((uint)(blockHeightRemainder * blockSize), blockNativePixelSize);
+
+ if (scaledWidth >= tSize.Width && scaledHeight >= tSize.Height)
+ {
+ blockPixelSize = blockSize;
+ return new Size(scaledWidth, scaledHeight);
+ }
+ }
+ }
+
+ return size;
+ }
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
index 8177e6dde8..c96f4acc21 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -30,10 +30,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
private readonly Configuration configuration;
+ private JpegFrame frame;
+
+ private IRawJpegData jpegData;
+
///
/// Jpeg component converters from decompressed spectral to color data.
///
- private JpegComponentPostProcessor[] componentProcessors;
+ private ComponentProcessor[] componentProcessors;
///
/// Color converter from jpeg color space to target pixel color space.
@@ -65,13 +69,26 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
///
private int pixelRowCounter;
+ ///
+ /// Represent target size after decoding for scaling decoding mode.
+ ///
+ ///
+ /// Null if no scaling is required.
+ ///
+ private Size? targetSize;
+
///
/// Initializes a new instance of the class.
///
/// The configuration.
- public SpectralConverter(Configuration configuration) =>
+ /// Optional target size for decoded image.
+ public SpectralConverter(Configuration configuration, Size? targetSize = null)
+ {
this.configuration = configuration;
+ this.targetSize = targetSize;
+ }
+
///
/// Gets converted pixel buffer.
///
@@ -85,6 +102,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
if (!this.Converted)
{
+ this.PrepareForDecoding();
+
int steps = (int)Math.Ceiling(this.pixelBuffer.Height / (float)this.pixelRowsPerStep);
for (int step = 0; step < steps; step++)
@@ -94,60 +113,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
}
}
- var buffer = this.pixelBuffer;
+ Buffer2D buffer = this.pixelBuffer;
this.pixelBuffer = null;
return buffer;
}
- ///
- public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
- {
- MemoryAllocator allocator = this.configuration.MemoryAllocator;
-
- // iteration data
- int majorBlockWidth = frame.Components.Max((component) => component.SizeInBlocks.Width);
- int majorVerticalSamplingFactor = frame.Components.Max((component) => component.SamplingFactors.Height);
-
- const int blockPixelHeight = 8;
- this.pixelRowsPerStep = majorVerticalSamplingFactor * blockPixelHeight;
-
- // pixel buffer for resulting image
- this.pixelBuffer = allocator.Allocate2D(
- frame.PixelWidth,
- frame.PixelHeight,
- this.configuration.PreferContiguousImageBuffers);
- this.paddedProxyPixelRow = allocator.Allocate(frame.PixelWidth + 3);
-
- // component processors from spectral to Rgba32
- const int blockPixelWidth = 8;
- var postProcessorBufferSize = new Size(majorBlockWidth * blockPixelWidth, this.pixelRowsPerStep);
- this.componentProcessors = new JpegComponentPostProcessor[frame.Components.Length];
- for (int i = 0; i < this.componentProcessors.Length; i++)
- {
- this.componentProcessors[i] = new JpegComponentPostProcessor(allocator, frame, jpegData, postProcessorBufferSize, frame.Components[i]);
- }
-
- // single 'stride' rgba32 buffer for conversion between spectral and TPixel
- this.rgbBuffer = allocator.Allocate(frame.PixelWidth * 3);
-
- // color converter from Rgba32 to TPixel
- this.colorConverter = this.GetColorConverter(frame, jpegData);
- }
-
- ///
- public override void ConvertStrideBaseline()
- {
- // Convert next pixel stride using single spectral `stride'
- // Note that zero passing eliminates the need of virtual call
- // from JpegComponentPostProcessor
- this.ConvertStride(spectralStep: 0);
-
- foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
- {
- cpp.ClearSpectralBuffers();
- }
- }
-
///
/// Converts single spectral jpeg stride to color stride.
///
@@ -198,12 +168,88 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.pixelRowCounter += this.pixelRowsPerStep;
}
+ ///
+ public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
+ {
+ this.frame = frame;
+ this.jpegData = jpegData;
+ }
+
+ ///
+ public override void PrepareForDecoding()
+ {
+ DebugGuard.IsTrue(this.colorConverter == null, "SpectralConverter.PrepareForDecoding() must be called once.");
+
+ MemoryAllocator allocator = this.configuration.MemoryAllocator;
+
+ // color converter from RGB to TPixel
+ JpegColorConverterBase converter = this.GetColorConverter(this.frame, this.jpegData);
+ this.colorConverter = converter;
+
+ // resulting image size
+ Size pixelSize = CalculateResultingImageSize(this.frame.PixelSize, this.targetSize, out int blockPixelSize);
+
+ // iteration data
+ int majorBlockWidth = this.frame.Components.Max((component) => component.SizeInBlocks.Width);
+ int majorVerticalSamplingFactor = this.frame.Components.Max((component) => component.SamplingFactors.Height);
+
+ this.pixelRowsPerStep = majorVerticalSamplingFactor * blockPixelSize;
+
+ // pixel buffer for resulting image
+ this.pixelBuffer = allocator.Allocate2D(
+ pixelSize.Width,
+ pixelSize.Height,
+ this.configuration.PreferContiguousImageBuffers);
+ this.paddedProxyPixelRow = allocator.Allocate(pixelSize.Width + 3);
+
+ // component processors from spectral to RGB
+ int bufferWidth = majorBlockWidth * blockPixelSize;
+ int batchSize = converter.ElementsPerBatch;
+ int batchRemainder = bufferWidth & (batchSize - 1);
+ var postProcessorBufferSize = new Size(bufferWidth + (batchSize - batchRemainder), this.pixelRowsPerStep);
+ this.componentProcessors = this.CreateComponentProcessors(this.frame, this.jpegData, blockPixelSize, postProcessorBufferSize);
+
+ // single 'stride' rgba32 buffer for conversion between spectral and TPixel
+ this.rgbBuffer = allocator.Allocate(pixelSize.Width * 3);
+ }
+
+ ///
+ public override void ConvertStrideBaseline()
+ {
+ // Convert next pixel stride using single spectral `stride'
+ // Note that zero passing eliminates extra virtual call
+ this.ConvertStride(spectralStep: 0);
+
+ foreach (ComponentProcessor cpp in this.componentProcessors)
+ {
+ cpp.ClearSpectralBuffers();
+ }
+ }
+
+ protected ComponentProcessor[] CreateComponentProcessors(JpegFrame frame, IRawJpegData jpegData, int blockPixelSize, Size processorBufferSize)
+ {
+ MemoryAllocator allocator = this.configuration.MemoryAllocator;
+ var componentProcessors = new ComponentProcessor[frame.Components.Length];
+ for (int i = 0; i < componentProcessors.Length; i++)
+ {
+ componentProcessors[i] = blockPixelSize switch
+ {
+ 4 => new DownScalingComponentProcessor2(allocator, frame, jpegData, processorBufferSize, frame.Components[i]),
+ 2 => new DownScalingComponentProcessor4(allocator, frame, jpegData, processorBufferSize, frame.Components[i]),
+ 1 => new DownScalingComponentProcessor8(allocator, frame, jpegData, processorBufferSize, frame.Components[i]),
+ _ => new DirectComponentProcessor(allocator, frame, jpegData, processorBufferSize, frame.Components[i]),
+ };
+ }
+
+ return componentProcessors;
+ }
+
///
public void Dispose()
{
if (this.componentProcessors != null)
{
- foreach (JpegComponentPostProcessor cpp in this.componentProcessors)
+ foreach (ComponentProcessor cpp in this.componentProcessors)
{
cpp.Dispose();
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
index 6e17762c72..c371a199e1 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
index 7274b51961..f8f7cdfe81 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
index e0b988b436..5ec8fd198e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.Intrinsic.cs
similarity index 81%
rename from src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs
rename to src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.Intrinsic.cs
index 8acc4b6269..19349e454b 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.Intrinsic.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.Intrinsics;
@@ -7,20 +7,8 @@ using System.Runtime.Intrinsics.X86;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
- internal static partial class FastFloatingPointDCT
+ internal static partial class FloatingPointDCT
{
-#pragma warning disable SA1310, SA1311, IDE1006 // naming rule violation warnings
- private static readonly Vector256 mm256_F_0_7071 = Vector256.Create(0.707106781f);
- private static readonly Vector256 mm256_F_0_3826 = Vector256.Create(0.382683433f);
- private static readonly Vector256 mm256_F_0_5411 = Vector256.Create(0.541196100f);
- private static readonly Vector256 mm256_F_1_3065 = Vector256.Create(1.306562965f);
-
- private static readonly Vector256 mm256_F_1_4142 = Vector256.Create(1.414213562f);
- private static readonly Vector256 mm256_F_1_8477 = Vector256.Create(1.847759065f);
- private static readonly Vector256 mm256_F_n1_0823 = Vector256.Create(-1.082392200f);
- private static readonly Vector256 mm256_F_n2_6131 = Vector256.Create(-2.613125930f);
-#pragma warning restore SA1310, SA1311, IDE1006
-
///
/// Apply floating point FDCT inplace using simd operations.
///
@@ -57,6 +45,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
block.V0 = Avx.Add(tmp10, tmp11);
block.V4 = Avx.Subtract(tmp10, tmp11);
+ Vector256 mm256_F_0_7071 = Vector256.Create(0.707106781f);
Vector256 z1 = Avx.Multiply(Avx.Add(tmp12, tmp13), mm256_F_0_7071);
block.V2 = Avx.Add(tmp13, z1);
block.V6 = Avx.Subtract(tmp13, z1);
@@ -66,9 +55,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
tmp11 = Avx.Add(tmp5, tmp6);
tmp12 = Avx.Add(tmp6, tmp7);
- Vector256 z5 = Avx.Multiply(Avx.Subtract(tmp10, tmp12), mm256_F_0_3826);
- Vector256 z2 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, mm256_F_0_5411, tmp10);
- Vector256 z4 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, mm256_F_1_3065, tmp12);
+ Vector256 z5 = Avx.Multiply(Avx.Subtract(tmp10, tmp12), Vector256.Create(0.382683433f)); // mm256_F_0_3826
+ Vector256 z2 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, Vector256.Create(0.541196100f), tmp10); // mm256_F_0_5411
+ Vector256 z4 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, Vector256.Create(1.306562965f), tmp12); // mm256_F_1_3065
Vector256 z3 = Avx.Multiply(tmp11, mm256_F_0_7071);
Vector256 z11 = Avx.Add(tmp7, z3);
@@ -109,6 +98,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
Vector256 tmp10 = Avx.Add(z5, tmp2);
Vector256 tmp11 = Avx.Subtract(z5, tmp2);
+ Vector256 mm256_F_1_4142 = Vector256.Create(1.414213562f);
Vector256 tmp13 = Avx.Add(tmp1, tmp3);
Vector256 tmp12 = SimdUtils.HwIntrinsics.MultiplySubstract(tmp13, Avx.Subtract(tmp1, tmp3), mm256_F_1_4142);
@@ -131,10 +121,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
tmp7 = Avx.Add(z11, z13);
tmp11 = Avx.Multiply(Avx.Subtract(z11, z13), mm256_F_1_4142);
- z5 = Avx.Multiply(Avx.Add(z10, z12), mm256_F_1_8477);
+ z5 = Avx.Multiply(Avx.Add(z10, z12), Vector256.Create(1.847759065f)); // mm256_F_1_8477
- tmp10 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, z12, mm256_F_n1_0823);
- tmp12 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, z10, mm256_F_n2_6131);
+ tmp10 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, z12, Vector256.Create(-1.082392200f)); // mm256_F_n1_0823
+ tmp12 = SimdUtils.HwIntrinsics.MultiplyAdd(z5, z10, Vector256.Create(-2.613125930f)); // mm256_F_n2_6131
tmp6 = Avx.Subtract(tmp12, tmp7);
tmp5 = Avx.Subtract(tmp11, tmp6);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs
similarity index 93%
rename from src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
rename to src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs
index e1bcff30f3..37ec6e1905 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/FloatingPointDCT.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -12,9 +12,12 @@ using System.Runtime.Intrinsics.X86;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
///
- /// Contains inaccurate, but fast forward and inverse DCT implementations.
+ /// Contains floating point forward and inverse DCT implementations
///
- internal static partial class FastFloatingPointDCT
+ ///
+ /// Based on "Arai, Agui and Nakajima" algorithm.
+ ///
+ internal static partial class FloatingPointDCT
{
#pragma warning disable SA1310, SA1311, IDE1006 // naming rules violation warnings
private static readonly Vector4 mm128_F_0_7071 = new(0.707106781f);
@@ -70,8 +73,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
ref float multipliersRef = ref MemoryMarshal.GetReference(AdjustmentCoefficients);
for (nint i = 0; i < Block8x8F.Size; i++)
{
- tableRef = 0.125f * tableRef * Unsafe.Add(ref multipliersRef, i);
- tableRef = ref Unsafe.Add(ref tableRef, 1);
+ ref float elemRef = ref Unsafe.Add(ref tableRef, i);
+ elemRef = 0.125f * elemRef * Unsafe.Add(ref multipliersRef, i);
}
// Spectral macroblocks are transposed before quantization
@@ -89,8 +92,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
ref float multipliersRef = ref MemoryMarshal.GetReference(AdjustmentCoefficients);
for (nint i = 0; i < Block8x8F.Size; i++)
{
- tableRef = 0.125f / (tableRef * Unsafe.Add(ref multipliersRef, i));
- tableRef = ref Unsafe.Add(ref tableRef, 1);
+ ref float elemRef = ref Unsafe.Add(ref tableRef, i);
+ elemRef = 0.125f / (elemRef * Unsafe.Add(ref multipliersRef, i));
}
// Spectral macroblocks are not transposed before quantization
@@ -103,7 +106,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Apply 2D floating point IDCT inplace.
///
///
- /// Input block must be dequantized before this method with table
+ /// Input block must be dequantized with quantization table
/// adjusted by .
///
/// Input block.
@@ -125,8 +128,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Apply 2D floating point IDCT inplace.
///
///
- /// Input block must be quantized after this method with table adjusted
- /// by .
+ /// Input block must be quantized after this method with quantization
+ /// table adjusted by .
///
/// Input block.
public static void TransformFDCT(ref Block8x8F block)
@@ -221,7 +224,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Apply floating point FDCT inplace using API.
///
/// Input block.
- public static void FDCT_Vector4(ref Block8x8F block)
+ private static void FDCT_Vector4(ref Block8x8F block)
{
// First pass - process columns
FDCT8x4_Vector4(ref block.V0L);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/JpegColorSpace.cs b/src/ImageSharp/Formats/Jpeg/Components/JpegColorSpace.cs
index c806855391..05494f68a8 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/JpegColorSpace.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/JpegColorSpace.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Quantization.cs b/src/ImageSharp/Formats/Jpeg/Components/Quantization.cs
index a5e823ddbd..5fd7da35e5 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Quantization.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Quantization.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
index d4a4c1cf45..c899cf3adb 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs
new file mode 100644
index 0000000000..037995ea13
--- /dev/null
+++ b/src/ImageSharp/Formats/Jpeg/Components/ScaledFloatingPointDCT.cs
@@ -0,0 +1,220 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+using System;
+using System.Runtime.CompilerServices;
+
+#pragma warning disable IDE0078
+namespace SixLabors.ImageSharp.Formats.Jpeg.Components
+{
+ ///
+ /// Contains floating point forward DCT implementations with built-in scaling.
+ ///
+ ///
+ /// Based on "Loeffler, Ligtenberg, and Moschytz" algorithm.
+ ///
+ internal static class ScaledFloatingPointDCT
+ {
+#pragma warning disable SA1310
+ private const float FP32_0_541196100 = 0.541196100f;
+ private const float FP32_0_765366865 = 0.765366865f;
+ private const float FP32_1_847759065 = 1.847759065f;
+ private const float FP32_0_211164243 = 0.211164243f;
+ private const float FP32_1_451774981 = 1.451774981f;
+ private const float FP32_2_172734803 = 2.172734803f;
+ private const float FP32_1_061594337 = 1.061594337f;
+ private const float FP32_0_509795579 = 0.509795579f;
+ private const float FP32_0_601344887 = 0.601344887f;
+ private const float FP32_0_899976223 = 0.899976223f;
+ private const float FP32_2_562915447 = 2.562915447f;
+ private const float FP32_0_720959822 = 0.720959822f;
+ private const float FP32_0_850430095 = 0.850430095f;
+ private const float FP32_1_272758580 = 1.272758580f;
+ private const float FP32_3_624509785 = 3.624509785f;
+#pragma warning restore SA1310
+
+ ///
+ /// Adjusts given quantization table for usage with IDCT algorithms
+ /// from .
+ ///
+ /// Quantization table to adjust.
+ public static void AdjustToIDCT(ref Block8x8F quantTable)
+ {
+ ref float tableRef = ref Unsafe.As(ref quantTable);
+ for (nint i = 0; i < Block8x8F.Size; i++)
+ {
+ ref float elemRef = ref Unsafe.Add(ref tableRef, i);
+ elemRef = 0.125f * elemRef;
+ }
+
+ // Spectral macroblocks are transposed before quantization
+ // so we must transpose quantization table
+ quantTable.TransposeInplace();
+ }
+
+ ///
+ /// Apply 2D floating point 'donwscaling' IDCT inplace producing
+ /// 8x8 -> 4x4 result.
+ ///
+ ///
+ /// Resulting matrix is stored in the top left 4x4 part of the
+ /// .
+ ///
+ /// Input block.
+ /// Dequantization table adjusted by .
+ /// Output range normalization value, 1/2 of the .
+ /// Maximum value of the output range.
+ public static void TransformIDCT_4x4(ref Block8x8F block, ref Block8x8F dequantTable, float normalizationValue, float maxValue)
+ {
+ for (int ctr = 0; ctr < 8; ctr++)
+ {
+ // Don't process row 4, second pass doesn't use it
+ if (ctr == 4)
+ {
+ continue;
+ }
+
+ // Even part
+ float tmp0 = block[(ctr * 8) + 0] * dequantTable[(ctr * 8) + 0] * 2;
+
+ float z2 = block[(ctr * 8) + 2] * dequantTable[(ctr * 8) + 2];
+ float z3 = block[(ctr * 8) + 6] * dequantTable[(ctr * 8) + 6];
+
+ float tmp2 = (z2 * FP32_1_847759065) + (z3 * -FP32_0_765366865);
+
+ float tmp10 = tmp0 + tmp2;
+ float tmp12 = tmp0 - tmp2;
+
+ // Odd part
+ float z1 = block[(ctr * 8) + 7] * dequantTable[(ctr * 8) + 7];
+ z2 = block[(ctr * 8) + 5] * dequantTable[(ctr * 8) + 5];
+ z3 = block[(ctr * 8) + 3] * dequantTable[(ctr * 8) + 3];
+ float z4 = block[(ctr * 8) + 1] * dequantTable[(ctr * 8) + 1];
+
+ tmp0 = (z1 * -FP32_0_211164243) +
+ (z2 * FP32_1_451774981) +
+ (z3 * -FP32_2_172734803) +
+ (z4 * FP32_1_061594337);
+
+ tmp2 = (z1 * -FP32_0_509795579) +
+ (z2 * -FP32_0_601344887) +
+ (z3 * FP32_0_899976223) +
+ (z4 * FP32_2_562915447);
+
+ // temporal result is saved to +4 shifted indices
+ // because result is saved into the top left 2x2 region of the
+ // input block
+ block[(ctr * 8) + 0 + 4] = (tmp10 + tmp2) / 2;
+ block[(ctr * 8) + 3 + 4] = (tmp10 - tmp2) / 2;
+ block[(ctr * 8) + 1 + 4] = (tmp12 + tmp0) / 2;
+ block[(ctr * 8) + 2 + 4] = (tmp12 - tmp0) / 2;
+ }
+
+ for (int ctr = 0; ctr < 4; ctr++)
+ {
+ // Even part
+ float tmp0 = block[ctr + (8 * 0) + 4] * 2;
+
+ float tmp2 = (block[ctr + (8 * 2) + 4] * FP32_1_847759065) + (block[ctr + (8 * 6) + 4] * -FP32_0_765366865);
+
+ float tmp10 = tmp0 + tmp2;
+ float tmp12 = tmp0 - tmp2;
+
+ // Odd part
+ float z1 = block[ctr + (8 * 7) + 4];
+ float z2 = block[ctr + (8 * 5) + 4];
+ float z3 = block[ctr + (8 * 3) + 4];
+ float z4 = block[ctr + (8 * 1) + 4];
+
+ tmp0 = (z1 * -FP32_0_211164243) +
+ (z2 * FP32_1_451774981) +
+ (z3 * -FP32_2_172734803) +
+ (z4 * FP32_1_061594337);
+
+ tmp2 = (z1 * -FP32_0_509795579) +
+ (z2 * -FP32_0_601344887) +
+ (z3 * FP32_0_899976223) +
+ (z4 * FP32_2_562915447);
+
+ // Save results to the top left 4x4 subregion
+ block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp2) / 2) + normalizationValue, 0, maxValue));
+ block[(ctr * 8) + 3] = MathF.Round(Numerics.Clamp(((tmp10 - tmp2) / 2) + normalizationValue, 0, maxValue));
+ block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp12 + tmp0) / 2) + normalizationValue, 0, maxValue));
+ block[(ctr * 8) + 2] = MathF.Round(Numerics.Clamp(((tmp12 - tmp0) / 2) + normalizationValue, 0, maxValue));
+ }
+ }
+
+ ///
+ /// Apply 2D floating point 'donwscaling' IDCT inplace producing
+ /// 8x8 -> 2x2 result.
+ ///
+ ///
+ /// Resulting matrix is stored in the top left 2x2 part of the
+ /// .
+ ///
+ /// Input block.
+ /// Dequantization table adjusted by .
+ /// Output range normalization value, 1/2 of the .
+ /// Maximum value of the output range.
+ public static void TransformIDCT_2x2(ref Block8x8F block, ref Block8x8F dequantTable, float normalizationValue, float maxValue)
+ {
+ for (int ctr = 0; ctr < 8; ctr++)
+ {
+ // Don't process rows 2/4/6, second pass doesn't use it
+ if (ctr == 2 || ctr == 4 || ctr == 6)
+ {
+ continue;
+ }
+
+ // Even part
+ float tmp0;
+ float z1 = block[(ctr * 8) + 0] * dequantTable[(ctr * 8) + 0];
+ float tmp10 = z1 * 4;
+
+ // Odd part
+ z1 = block[(ctr * 8) + 7] * dequantTable[(ctr * 8) + 7];
+ tmp0 = z1 * -FP32_0_720959822;
+ z1 = block[(ctr * 8) + 5] * dequantTable[(ctr * 8) + 5];
+ tmp0 += z1 * FP32_0_850430095;
+ z1 = block[(ctr * 8) + 3] * dequantTable[(ctr * 8) + 3];
+ tmp0 += z1 * -FP32_1_272758580;
+ z1 = block[(ctr * 8) + 1] * dequantTable[(ctr * 8) + 1];
+ tmp0 += z1 * FP32_3_624509785;
+
+ // temporal result is saved to +2 shifted indices
+ // because result is saved into the top left 2x2 region of the
+ // input block
+ block[(ctr * 8) + 2] = (tmp10 + tmp0) / 4;
+ block[(ctr * 8) + 3] = (tmp10 - tmp0) / 4;
+ }
+
+ for (int ctr = 0; ctr < 2; ctr++)
+ {
+ // Even part
+ float tmp10 = block[ctr + (8 * 0) + 2] * 4;
+
+ // Odd part
+ float tmp0 = (block[ctr + (8 * 7) + 2] * -FP32_0_720959822) +
+ (block[ctr + (8 * 5) + 2] * FP32_0_850430095) +
+ (block[ctr + (8 * 3) + 2] * -FP32_1_272758580) +
+ (block[ctr + (8 * 1) + 2] * FP32_3_624509785);
+
+ // Save results to the top left 2x2 subregion
+ block[(ctr * 8) + 0] = MathF.Round(Numerics.Clamp(((tmp10 + tmp0) / 4) + normalizationValue, 0, maxValue));
+ block[(ctr * 8) + 1] = MathF.Round(Numerics.Clamp(((tmp10 - tmp0) / 4) + normalizationValue, 0, maxValue));
+ }
+ }
+
+ ///
+ /// Apply 2D floating point 'donwscaling' IDCT inplace producing
+ /// 8x8 -> 1x1 result.
+ ///
+ /// Direct current term value from input block.
+ /// Dequantization value.
+ /// Output range normalization value, 1/2 of the .
+ /// Maximum value of the output range.
+ public static float TransformIDCT_1x1(float dc, float dequantizer, float normalizationValue, float maxValue)
+ => MathF.Round(Numerics.Clamp((dc * dequantizer) + normalizationValue, 0, maxValue));
+ }
+}
+#pragma warning restore IDE0078
diff --git a/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
index 12d21648f4..fa7778cbae 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.Intrinsic.cs b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.Intrinsic.cs
index 850de26c30..ee1ec501b9 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.Intrinsic.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.Intrinsic.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
#if SUPPORTS_RUNTIME_INTRINSICS
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
index ab80b3ae67..c18333a920 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
index 0b49ddfe62..76874b7ffd 100644
--- a/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
index 449db9d81b..f9c7828caf 100644
--- a/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
index 699eb95a35..e98f146a20 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
index 20edf40379..a4ba8725e8 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
index 22a9801b8f..7f23d1ac85 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
@@ -1,8 +1,10 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
+using SixLabors.ImageSharp.IO;
+using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg
@@ -29,6 +31,42 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public Image Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
=> this.Decode(configuration, stream, cancellationToken);
+ ///
+ /// Placeholder summary.
+ ///
+ /// Placeholder2
+ /// Placeholder3
+ /// Placeholder4
+ /// Placeholder5
+ /// Placeholder6
+ internal Image DecodeInto(Configuration configuration, Stream stream, Size targetSize, CancellationToken cancellationToken)
+ => this.DecodeInto(configuration, stream, targetSize, cancellationToken);
+
+ ///
+ /// Decodes and downscales the image from the specified stream if possible.
+ ///
+ /// The pixel format.
+ /// Configuration.
+ /// Stream.
+ /// Target size.
+ /// Cancellation token.
+ internal Image DecodeInto(Configuration configuration, Stream stream, Size targetSize, CancellationToken cancellationToken)
+ where TPixel : unmanaged, IPixel
+ {
+ Guard.NotNull(stream, nameof(stream));
+
+ using var decoder = new JpegDecoderCore(configuration, this);
+ using var bufferedReadStream = new BufferedReadStream(configuration, stream);
+ try
+ {
+ return decoder.DecodeInto(bufferedReadStream, targetSize, cancellationToken);
+ }
+ catch (InvalidMemoryOperationException ex)
+ {
+ throw new InvalidImageContentException(((IImageDecoderInternals)decoder).Dimensions, ex);
+ }
+ }
+
///
public IImageInfo Identify(Configuration configuration, Stream stream, CancellationToken cancellationToken)
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 3c2aa6d981..7fc64bd057 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -85,6 +85,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
private byte[] xmpData;
+ ///
+ /// Whether the image has a APP14 adobe marker. This is needed to determine image encoded colorspace.
+ ///
+ private bool hasAdobeMarker;
+
///
/// Contains information about the JFIF marker.
///
@@ -159,71 +164,85 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
///
/// Finds the next file marker within the byte stream.
///
- /// The buffer to read file markers to.
/// The input stream.
- /// The
- public static JpegFileMarker FindNextFileMarker(byte[] marker, BufferedReadStream stream)
+ /// The .
+ public static JpegFileMarker FindNextFileMarker(BufferedReadStream stream)
{
- int value = stream.Read(marker, 0, 2);
-
- if (value == 0)
+ while (true)
{
- return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
- }
+ int b = stream.ReadByte();
+ if (b == -1)
+ {
+ return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
+ }
- if (marker[0] == JpegConstants.Markers.XFF)
- {
- // According to Section B.1.1.2:
- // "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code 0xFF."
- int m = marker[1];
- while (m == JpegConstants.Markers.XFF)
+ // Found a marker.
+ if (b == JpegConstants.Markers.XFF)
{
- int suffix = stream.ReadByte();
- if (suffix == -1)
+ while (b == JpegConstants.Markers.XFF)
{
- return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
+ // Loop here to discard any padding FF bytes on terminating marker.
+ b = stream.ReadByte();
+ if (b == -1)
+ {
+ return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
+ }
}
- m = suffix;
+ // Found a valid marker. Exit loop
+ if (b is not 0 and (< JpegConstants.Markers.RST0 or > JpegConstants.Markers.RST7))
+ {
+ return new JpegFileMarker((byte)(uint)b, stream.Position - 2);
+ }
}
-
- return new JpegFileMarker((byte)m, stream.Position - 2);
}
-
- return new JpegFileMarker(marker[1], stream.Position - 2, true);
}
///
public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
- {
- using var spectralConverter = new SpectralConverter(this.Configuration);
+ => this.Decode(stream, targetSize: null, cancellationToken);
- this.ParseStream(stream, spectralConverter, cancellationToken);
+ ///
+ public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
+ {
+ this.ParseStream(stream, spectralConverter: null, cancellationToken);
this.InitExifProfile();
this.InitIccProfile();
this.InitIptcProfile();
this.InitXmpProfile();
this.InitDerivedMetadataProperties();
- return new Image(
- this.Configuration,
- spectralConverter.GetPixelBuffer(cancellationToken),
- this.Metadata);
+ Size pixelSize = this.Frame.PixelSize;
+ return new ImageInfo(new PixelTypeInfo(this.Frame.BitsPerPixel), pixelSize.Width, pixelSize.Height, this.Metadata);
}
- ///
- public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
+ ///
+ /// Decodes and downscales the image from the specified stream if possible.
+ ///
+ /// The pixel format.
+ /// Stream.
+ /// Target size.
+ /// Cancellation token.
+ internal Image DecodeInto(BufferedReadStream stream, Size targetSize, CancellationToken cancellationToken)
+ where TPixel : unmanaged, IPixel
+ => this.Decode(stream, targetSize, cancellationToken);
+
+ private Image Decode(BufferedReadStream stream, Size? targetSize, CancellationToken cancellationToken)
+ where TPixel : unmanaged, IPixel
{
- this.ParseStream(stream, spectralConverter: null, cancellationToken);
+ using var spectralConverter = new SpectralConverter(this.Configuration, targetSize);
+ this.ParseStream(stream, spectralConverter, cancellationToken);
this.InitExifProfile();
this.InitIccProfile();
this.InitIptcProfile();
this.InitXmpProfile();
this.InitDerivedMetadataProperties();
- Size pixelSize = this.Frame.PixelSize;
- return new ImageInfo(new PixelTypeInfo(this.Frame.BitsPerPixel), pixelSize.Width, pixelSize.Height, this.Metadata);
+ return new Image(
+ this.Configuration,
+ spectralConverter.GetPixelBuffer(cancellationToken),
+ this.Metadata);
}
///
@@ -326,15 +345,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
JpegThrowHelper.ThrowInvalidImageContentException("Missing SOI marker.");
}
- stream.Read(this.markerBuffer, 0, 2);
- byte marker = this.markerBuffer[1];
- fileMarker = new JpegFileMarker(marker, (int)stream.Position - 2);
+ fileMarker = FindNextFileMarker(stream);
this.QuantizationTables ??= new Block8x8F[4];
// Break only when we discover a valid EOI marker.
// https://github.com/SixLabors/ImageSharp/issues/695
- while (fileMarker.Marker != JpegConstants.Markers.EOI
- || (fileMarker.Marker == JpegConstants.Markers.EOI && fileMarker.Invalid))
+ while (fileMarker.Marker != JpegConstants.Markers.EOI)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -486,7 +502,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
// Read on.
- fileMarker = FindNextFileMarker(this.markerBuffer, stream);
+ fileMarker = FindNextFileMarker(stream);
}
this.Metadata.GetJpegMetadata().Interleaved = this.Frame.Interleaved;
@@ -503,11 +519,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
}
///
- /// Returns the correct colorspace based on the image component count and the jpeg frame component id's.
+ /// Returns encoded colorspace based on the adobe APP14 marker.
///
- /// The number of components.
+ /// Number of components.
+ /// Parsed adobe APP14 marker.
/// The
- private JpegColorSpace DeduceJpegColorSpace(byte componentCount)
+ internal static JpegColorSpace DeduceJpegColorSpace(byte componentCount, ref AdobeMarker adobeMarker)
{
if (componentCount == 1)
{
@@ -516,27 +533,48 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
if (componentCount == 3)
{
- if (!this.adobe.Equals(default) && this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown)
+ if (adobeMarker.ColorTransform == JpegConstants.Adobe.ColorTransformUnknown)
{
return JpegColorSpace.RGB;
}
- // If the component Id's are R, G, B in ASCII the colorspace is RGB and not YCbCr.
- if (this.Components[2].Id == 66 && this.Components[1].Id == 71 && this.Components[0].Id == 82)
+ return JpegColorSpace.YCbCr;
+ }
+
+ if (componentCount == 4)
+ {
+ if (adobeMarker.ColorTransform == JpegConstants.Adobe.ColorTransformYcck)
{
- return JpegColorSpace.RGB;
+ return JpegColorSpace.Ycck;
}
- // Some images are poorly encoded and contain incorrect colorspace transform metadata.
- // We ignore that and always fall back to the default colorspace.
+ return JpegColorSpace.Cmyk;
+ }
+
+ JpegThrowHelper.ThrowNotSupportedComponentCount(componentCount);
+ return default;
+ }
+
+ ///
+ /// Returns encoded colorspace based on the component count.
+ ///
+ /// Number of components.
+ /// The
+ internal static JpegColorSpace DeduceJpegColorSpace(byte componentCount)
+ {
+ if (componentCount == 1)
+ {
+ return JpegColorSpace.Grayscale;
+ }
+
+ if (componentCount == 3)
+ {
return JpegColorSpace.YCbCr;
}
if (componentCount == 4)
{
- return this.adobe.ColorTransform == JpegConstants.Adobe.ColorTransformYcck
- ? JpegColorSpace.Ycck
- : JpegColorSpace.Cmyk;
+ return JpegColorSpace.Cmyk;
}
JpegThrowHelper.ThrowNotSupportedComponentCount(componentCount);
@@ -1006,7 +1044,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
stream.Read(this.temp, 0, MarkerLength);
remaining -= MarkerLength;
- AdobeMarker.TryParse(this.temp, out this.adobe);
+ if (AdobeMarker.TryParse(this.temp, out this.adobe))
+ {
+ this.hasAdobeMarker = true;
+ }
if (remaining > 0)
{
@@ -1114,9 +1155,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
break;
}
}
-
- // Adjusting table for IDCT step during decompression
- FastFloatingPointDCT.AdjustToIDCT(ref table);
}
}
@@ -1203,7 +1241,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
int maxH = 0;
int maxV = 0;
int index = 0;
- for (int i = 0; i < componentCount; i++)
+ for (int i = 0; i < this.Frame.Components.Length; i++)
{
// 1 byte: component identifier
byte componentId = this.temp[index];
@@ -1254,7 +1292,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
index += componentBytes;
}
- this.ColorSpace = this.DeduceJpegColorSpace(componentCount);
+ this.ColorSpace = this.hasAdobeMarker
+ ? DeduceJpegColorSpace(componentCount, ref this.adobe)
+ : DeduceJpegColorSpace(componentCount);
this.Metadata.GetJpegMetadata().ColorType = this.DeduceJpegColorType();
if (!metadataOnly)
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
index 5817eaa335..c86f37dd8a 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
index c8dd763e71..eb1005cb59 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncodingColor.cs b/src/ImageSharp/Formats/Jpeg/JpegEncodingColor.cs
index f803c830e5..e6a83b0a5d 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegEncodingColor.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegEncodingColor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg
{
diff --git a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
index 241aa3d8f9..dd98849012 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
index 27f859c471..fbbe210ff0 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs b/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
index ef253cfebc..63127f1eca 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
diff --git a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
index 1073ffff78..cbaafbc4e5 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
@@ -51,5 +51,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNotSupportedComponentCount(int componentCount) => throw new NotSupportedException($"Images with {componentCount} components are not supported.");
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ public static void ThrowNotSupportedColorSpace() => throw new NotSupportedException("Image color space could not be deduced.");
}
}
diff --git a/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs b/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
index d154f3490f..cc89685a31 100644
--- a/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
index 33af30434c..c5d28002a0 100644
--- a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs b/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
index 332ab9b50d..67cbdd5220 100644
--- a/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
+++ b/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs b/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
index 581d3e592b..4e740ce8e5 100644
--- a/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
+++ b/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using SixLabors.ImageSharp.IO;
diff --git a/src/ImageSharp/Formats/Pbm/IPbmEncoderOptions.cs b/src/ImageSharp/Formats/Pbm/IPbmEncoderOptions.cs
index 988d9e560e..fb413c3716 100644
--- a/src/ImageSharp/Formats/Pbm/IPbmEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Pbm/IPbmEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/MetadataExtensions.cs b/src/ImageSharp/Formats/Pbm/MetadataExtensions.cs
index cce8fb3187..d63d66b84e 100644
--- a/src/ImageSharp/Formats/Pbm/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Pbm/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Pbm;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Pbm/PbmColorType.cs b/src/ImageSharp/Formats/Pbm/PbmColorType.cs
index 827f19344b..955654f01e 100644
--- a/src/ImageSharp/Formats/Pbm/PbmColorType.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmColorType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/PbmComponentType.cs b/src/ImageSharp/Formats/Pbm/PbmComponentType.cs
index 26272021ce..de5c0ec94e 100644
--- a/src/ImageSharp/Formats/Pbm/PbmComponentType.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmComponentType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs b/src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs
index 172bda667f..fa521a3661 100644
--- a/src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/PbmConstants.cs b/src/ImageSharp/Formats/Pbm/PbmConstants.cs
index 912ffaf856..6c805d406c 100644
--- a/src/ImageSharp/Formats/Pbm/PbmConstants.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
index 97a9cb7d75..835582bb69 100644
--- a/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
index 749fc0292b..5a549f7558 100644
--- a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs
index 75d6660635..9bfd7192d7 100644
--- a/src/ImageSharp/Formats/Pbm/PbmEncoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs
index 9d1f39edf3..25c7ee450e 100644
--- a/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Text;
diff --git a/src/ImageSharp/Formats/Pbm/PbmEncoding.cs b/src/ImageSharp/Formats/Pbm/PbmEncoding.cs
index be7fb909f3..aa42e85c28 100644
--- a/src/ImageSharp/Formats/Pbm/PbmEncoding.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmEncoding.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/PbmFormat.cs b/src/ImageSharp/Formats/Pbm/PbmFormat.cs
index 5ffb49652f..e644250a11 100644
--- a/src/ImageSharp/Formats/Pbm/PbmFormat.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs b/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs
index 15bacc4de7..b8d776a37d 100644
--- a/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Pbm/PbmMetadata.cs b/src/ImageSharp/Formats/Pbm/PbmMetadata.cs
index a00ae46dee..6806ffdb93 100644
--- a/src/ImageSharp/Formats/Pbm/PbmMetadata.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Pbm
{
diff --git a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
index aeb527dd20..203cd18f1e 100644
--- a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Pbm/PlainEncoder.cs b/src/ImageSharp/Formats/Pbm/PlainEncoder.cs
index a64ae38a74..b858d1e63a 100644
--- a/src/ImageSharp/Formats/Pbm/PlainEncoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PlainEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs
index afa3b19a22..0d15eebc73 100644
--- a/src/ImageSharp/Formats/PixelTypeInfo.cs
+++ b/src/ImageSharp/Formats/PixelTypeInfo.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Formats/Png/Adam7.cs b/src/ImageSharp/Formats/Png/Adam7.cs
index 50792cae18..788ff30b69 100644
--- a/src/ImageSharp/Formats/Png/Adam7.cs
+++ b/src/ImageSharp/Formats/Png/Adam7.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs b/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
index daf653532d..8ad2c5a4ab 100644
--- a/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
+++ b/src/ImageSharp/Formats/Png/Chunks/PhysicalChunkData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
index 44a16f154e..b381442bd8 100644
--- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/FilterType.cs b/src/ImageSharp/Formats/Png/Filters/FilterType.cs
index bd6aa3c595..a3a5b51b67 100644
--- a/src/ImageSharp/Formats/Png/Filters/FilterType.cs
+++ b/src/ImageSharp/Formats/Png/Filters/FilterType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
index 8fa4b3aad0..fd2d9eab49 100644
--- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
index 0553eb46a9..03d8834542 100644
--- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
index eaa4dc0344..a7044837e1 100644
--- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
index 0d24d9c5d5..c5003d1114 100644
--- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
+++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Numerics;
diff --git a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
index 4b09c5b1ca..873abc1fd7 100644
--- a/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
index 2c05019eda..1bc785eed6 100644
--- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
diff --git a/src/ImageSharp/Formats/Png/MetadataExtensions.cs b/src/ImageSharp/Formats/Png/MetadataExtensions.cs
index b7c2cccf5b..24417eb1b3 100644
--- a/src/ImageSharp/Formats/Png/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Png/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Png/PngBitDepth.cs b/src/ImageSharp/Formats/Png/PngBitDepth.cs
index e03f80f286..50e76326e5 100644
--- a/src/ImageSharp/Formats/Png/PngBitDepth.cs
+++ b/src/ImageSharp/Formats/Png/PngBitDepth.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
// Note the value assignment, This will allow us to add 1, 2, and 4 bit encoding when we support it.
namespace SixLabors.ImageSharp.Formats.Png
diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs
index 7b5f390f12..09270cd524 100644
--- a/src/ImageSharp/Formats/Png/PngChunk.cs
+++ b/src/ImageSharp/Formats/Png/PngChunk.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Png/PngChunkFilter.cs b/src/ImageSharp/Formats/Png/PngChunkFilter.cs
index 4d6a20bc91..f0feb9e6a2 100644
--- a/src/ImageSharp/Formats/Png/PngChunkFilter.cs
+++ b/src/ImageSharp/Formats/Png/PngChunkFilter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Png/PngChunkType.cs b/src/ImageSharp/Formats/Png/PngChunkType.cs
index 39f19f232b..213a4a7937 100644
--- a/src/ImageSharp/Formats/Png/PngChunkType.cs
+++ b/src/ImageSharp/Formats/Png/PngChunkType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngColorType.cs b/src/ImageSharp/Formats/Png/PngColorType.cs
index ce631b1a1b..139554c7cc 100644
--- a/src/ImageSharp/Formats/Png/PngColorType.cs
+++ b/src/ImageSharp/Formats/Png/PngColorType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngCompressionLevel.cs b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
index 961f9b05b8..df098b7beb 100644
--- a/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
+++ b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.ComponentModel;
diff --git a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
index 9a1f4b2b37..bbf2f4cb8f 100644
--- a/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Png/PngConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs
index fcc8fd992c..69fae6af91 100644
--- a/src/ImageSharp/Formats/Png/PngConstants.cs
+++ b/src/ImageSharp/Formats/Png/PngConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs
index 0b233848ad..f1a03b83e3 100644
--- a/src/ImageSharp/Formats/Png/PngDecoder.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 12770bc521..784d9aa11f 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -19,6 +19,7 @@ using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
+using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.PixelFormats;
@@ -205,6 +206,9 @@ namespace SixLabors.ImageSharp.Formats.Png
this.MergeOrSetExifProfile(metadata, new ExifProfile(exifData), replaceExistingKeys: true);
}
+ break;
+ case PngChunkType.EmbeddedColorProfile:
+ this.ReadColorProfileChunk(metadata, chunk.Data.GetSpan());
break;
case PngChunkType.End:
goto EOF;
@@ -1174,6 +1178,76 @@ namespace SixLabors.ImageSharp.Formats.Png
return true;
}
+ ///
+ /// Reads the color profile chunk. The data is stored similar to the zTXt chunk.
+ ///
+ /// The metadata.
+ /// The bytes containing the profile.
+ private void ReadColorProfileChunk(ImageMetadata metadata, ReadOnlySpan data)
+ {
+ int zeroIndex = data.IndexOf((byte)0);
+ if (zeroIndex is < PngConstants.MinTextKeywordLength or > PngConstants.MaxTextKeywordLength)
+ {
+ return;
+ }
+
+ byte compressionMethod = data[zeroIndex + 1];
+ if (compressionMethod != 0)
+ {
+ // Only compression method 0 is supported (zlib datastream with deflate compression).
+ return;
+ }
+
+ ReadOnlySpan keywordBytes = data.Slice(0, zeroIndex);
+ if (!this.TryReadTextKeyword(keywordBytes, out string name))
+ {
+ return;
+ }
+
+ ReadOnlySpan compressedData = data.Slice(zeroIndex + 2);
+
+ if (this.TryUncompressZlibData(compressedData, out byte[] iccpProfileBytes))
+ {
+ metadata.IccProfile = new IccProfile(iccpProfileBytes);
+ }
+ }
+
+ ///
+ /// Tries to un-compress zlib compressed data.
+ ///
+ /// The compressed data.
+ /// The uncompressed bytes array.
+ /// True, if de-compressing was successful.
+ private unsafe bool TryUncompressZlibData(ReadOnlySpan compressedData, out byte[] uncompressedBytesArray)
+ {
+ fixed (byte* compressedDataBase = compressedData)
+ {
+ using (IMemoryOwner destBuffer = this.memoryAllocator.Allocate(this.Configuration.StreamProcessingBufferSize))
+ using (var memoryStreamOutput = new MemoryStream(compressedData.Length))
+ using (var memoryStreamInput = new UnmanagedMemoryStream(compressedDataBase, compressedData.Length))
+ using (var bufferedStream = new BufferedReadStream(this.Configuration, memoryStreamInput))
+ using (var inflateStream = new ZlibInflateStream(bufferedStream))
+ {
+ Span destUncompressedData = destBuffer.GetSpan();
+ if (!inflateStream.AllocateNewBytes(compressedData.Length, false))
+ {
+ uncompressedBytesArray = Array.Empty();
+ return false;
+ }
+
+ int bytesRead = inflateStream.CompressedStream.Read(destUncompressedData, 0, destUncompressedData.Length);
+ while (bytesRead != 0)
+ {
+ memoryStreamOutput.Write(destUncompressedData.Slice(0, bytesRead));
+ bytesRead = inflateStream.CompressedStream.Read(destUncompressedData, 0, destUncompressedData.Length);
+ }
+
+ uncompressedBytesArray = memoryStreamOutput.ToArray();
+ return true;
+ }
+ }
+ }
+
///
/// Compares two ReadOnlySpan<char>s in a case-insensitive method.
/// This is only needed because older frameworks are missing the extension method.
@@ -1306,7 +1380,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
else if (this.IsXmpTextData(keywordBytes))
{
- XmpProfile xmpProfile = new XmpProfile(data.Slice(dataStartIdx).ToArray());
+ var xmpProfile = new XmpProfile(data.Slice(dataStartIdx).ToArray());
metadata.XmpProfile = xmpProfile;
}
else
@@ -1325,29 +1399,14 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The .
private bool TryUncompressTextData(ReadOnlySpan compressedData, Encoding encoding, out string value)
{
- using (var memoryStream = new MemoryStream(compressedData.ToArray()))
- using (var bufferedStream = new BufferedReadStream(this.Configuration, memoryStream))
- using (var inflateStream = new ZlibInflateStream(bufferedStream))
+ if (this.TryUncompressZlibData(compressedData, out byte[] uncompressedData))
{
- if (!inflateStream.AllocateNewBytes(compressedData.Length, false))
- {
- value = null;
- return false;
- }
-
- var uncompressedBytes = new List();
-
- // Note: this uses a buffer which is only 4 bytes long to read the stream, maybe allocating a larger buffer makes sense here.
- int bytesRead = inflateStream.CompressedStream.Read(this.buffer, 0, this.buffer.Length);
- while (bytesRead != 0)
- {
- uncompressedBytes.AddRange(this.buffer.AsSpan(0, bytesRead).ToArray());
- bytesRead = inflateStream.CompressedStream.Read(this.buffer, 0, this.buffer.Length);
- }
-
- value = encoding.GetString(uncompressedBytes.ToArray());
+ value = encoding.GetString(uncompressedData);
return true;
}
+
+ value = null;
+ return false;
}
///
diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs
index e72e8d3d55..31e0c17c54 100644
--- a/src/ImageSharp/Formats/Png/PngEncoder.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index c443c0fcf1..9ae8f299a2 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -87,6 +87,11 @@ namespace SixLabors.ImageSharp.Formats.Png
///
private IMemoryOwner currentScanline;
+ ///
+ /// The color profile name.
+ ///
+ private const string ColorProfileName = "ICC Profile";
+
///
/// Initializes a new instance of the class.
///
@@ -134,6 +139,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.WriteHeaderChunk(stream);
this.WriteGammaChunk(stream);
+ this.WriteColorProfileChunk(stream, metadata);
this.WritePaletteChunk(stream, quantized);
this.WriteTransparencyChunk(stream, pngMetadata);
this.WritePhysicalChunk(stream, metadata);
@@ -656,7 +662,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
///
- /// Writes an iTXT chunk, containing the XMP metdata to the stream, if such profile is present in the metadata.
+ /// Writes an iTXT chunk, containing the XMP metadata to the stream, if such profile is present in the metadata.
///
/// The containing image data.
/// The image metadata.
@@ -673,7 +679,7 @@ namespace SixLabors.ImageSharp.Formats.Png
return;
}
- var xmpData = meta.XmpProfile.Data;
+ byte[] xmpData = meta.XmpProfile.Data;
if (xmpData.Length == 0)
{
@@ -687,19 +693,49 @@ namespace SixLabors.ImageSharp.Formats.Png
PngConstants.XmpKeyword.CopyTo(payload);
int bytesWritten = PngConstants.XmpKeyword.Length;
- // Write the iTxt header (all zeros in this case)
- payload[bytesWritten++] = 0;
- payload[bytesWritten++] = 0;
- payload[bytesWritten++] = 0;
- payload[bytesWritten++] = 0;
- payload[bytesWritten++] = 0;
+ // Write the iTxt header (all zeros in this case).
+ Span iTxtHeader = payload.Slice(bytesWritten);
+ iTxtHeader[4] = 0;
+ iTxtHeader[3] = 0;
+ iTxtHeader[2] = 0;
+ iTxtHeader[1] = 0;
+ iTxtHeader[0] = 0;
+ bytesWritten += 5;
- // And the XMP data itself
+ // And the XMP data itself.
xmpData.CopyTo(payload.Slice(bytesWritten));
this.WriteChunk(stream, PngChunkType.InternationalText, payload);
}
}
+ ///
+ /// Writes the color profile chunk.
+ ///
+ /// The stream to write to.
+ /// The image meta data.
+ private void WriteColorProfileChunk(Stream stream, ImageMetadata metaData)
+ {
+ if (metaData.IccProfile is null)
+ {
+ return;
+ }
+
+ byte[] iccProfileBytes = metaData.IccProfile.ToByteArray();
+
+ byte[] compressedData = this.GetZlibCompressedBytes(iccProfileBytes);
+ int payloadLength = ColorProfileName.Length + compressedData.Length + 2;
+ using (IMemoryOwner owner = this.memoryAllocator.Allocate(payloadLength))
+ {
+ Span outputBytes = owner.GetSpan();
+ PngConstants.Encoding.GetBytes(ColorProfileName).CopyTo(outputBytes);
+ int bytesWritten = ColorProfileName.Length;
+ outputBytes[bytesWritten++] = 0; // Null separator.
+ outputBytes[bytesWritten++] = 0; // Compression.
+ compressedData.CopyTo(outputBytes.Slice(bytesWritten));
+ this.WriteChunk(stream, PngChunkType.EmbeddedColorProfile, outputBytes);
+ }
+ }
+
///
/// Writes a text chunk to the stream. Can be either a tTXt, iTXt or zTXt chunk,
/// depending whether the text contains any latin characters or should be compressed.
@@ -727,13 +763,12 @@ namespace SixLabors.ImageSharp.Formats.Png
}
}
- if (hasUnicodeCharacters || (!string.IsNullOrWhiteSpace(textData.LanguageTag) ||
- !string.IsNullOrWhiteSpace(textData.TranslatedKeyword)))
+ if (hasUnicodeCharacters || (!string.IsNullOrWhiteSpace(textData.LanguageTag) || !string.IsNullOrWhiteSpace(textData.TranslatedKeyword)))
{
// Write iTXt chunk.
byte[] keywordBytes = PngConstants.Encoding.GetBytes(textData.Keyword);
byte[] textBytes = textData.Value.Length > this.options.TextCompressionThreshold
- ? this.GetCompressedTextBytes(PngConstants.TranslatedEncoding.GetBytes(textData.Value))
+ ? this.GetZlibCompressedBytes(PngConstants.TranslatedEncoding.GetBytes(textData.Value))
: PngConstants.TranslatedEncoding.GetBytes(textData.Value);
byte[] translatedKeyword = PngConstants.TranslatedEncoding.GetBytes(textData.TranslatedKeyword);
@@ -772,18 +807,17 @@ namespace SixLabors.ImageSharp.Formats.Png
if (textData.Value.Length > this.options.TextCompressionThreshold)
{
// Write zTXt chunk.
- byte[] compressedData =
- this.GetCompressedTextBytes(PngConstants.Encoding.GetBytes(textData.Value));
+ byte[] compressedData = this.GetZlibCompressedBytes(PngConstants.Encoding.GetBytes(textData.Value));
int payloadLength = textData.Keyword.Length + compressedData.Length + 2;
using (IMemoryOwner owner = this.memoryAllocator.Allocate(payloadLength))
{
Span outputBytes = owner.GetSpan();
PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes);
int bytesWritten = textData.Keyword.Length;
- outputBytes[bytesWritten++] = 0;
- outputBytes[bytesWritten++] = 0;
+ outputBytes[bytesWritten++] = 0; // Null separator.
+ outputBytes[bytesWritten++] = 0; // Compression.
compressedData.CopyTo(outputBytes.Slice(bytesWritten));
- this.WriteChunk(stream, PngChunkType.CompressedText, outputBytes.ToArray());
+ this.WriteChunk(stream, PngChunkType.CompressedText, outputBytes);
}
}
else
@@ -796,9 +830,8 @@ namespace SixLabors.ImageSharp.Formats.Png
PngConstants.Encoding.GetBytes(textData.Keyword).CopyTo(outputBytes);
int bytesWritten = textData.Keyword.Length;
outputBytes[bytesWritten++] = 0;
- PngConstants.Encoding.GetBytes(textData.Value)
- .CopyTo(outputBytes.Slice(bytesWritten));
- this.WriteChunk(stream, PngChunkType.Text, outputBytes.ToArray());
+ PngConstants.Encoding.GetBytes(textData.Value).CopyTo(outputBytes.Slice(bytesWritten));
+ this.WriteChunk(stream, PngChunkType.Text, outputBytes);
}
}
}
@@ -808,15 +841,15 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Compresses a given text using Zlib compression.
///
- /// The text bytes to compress.
- /// The compressed text byte array.
- private byte[] GetCompressedTextBytes(byte[] textBytes)
+ /// The bytes to compress.
+ /// The compressed byte array.
+ private byte[] GetZlibCompressedBytes(byte[] dataBytes)
{
using (var memoryStream = new MemoryStream())
{
using (var deflateStream = new ZlibDeflateStream(this.memoryAllocator, memoryStream, this.options.CompressionLevel))
{
- deflateStream.Write(textBytes);
+ deflateStream.Write(dataBytes);
}
return memoryStream.ToArray();
diff --git a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
index 5717ff0d63..99f64f2387 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
index 0bcea037ab..aaf1071cfc 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Processing.Processors.Quantization;
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
index 1250db6fe0..bed20fd415 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Advanced;
diff --git a/src/ImageSharp/Formats/Png/PngFilterMethod.cs b/src/ImageSharp/Formats/Png/PngFilterMethod.cs
index c6d466ac39..0e76fc91b2 100644
--- a/src/ImageSharp/Formats/Png/PngFilterMethod.cs
+++ b/src/ImageSharp/Formats/Png/PngFilterMethod.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngFormat.cs b/src/ImageSharp/Formats/Png/PngFormat.cs
index 3c867e0bd7..df222008be 100644
--- a/src/ImageSharp/Formats/Png/PngFormat.cs
+++ b/src/ImageSharp/Formats/Png/PngFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Png/PngHeader.cs b/src/ImageSharp/Formats/Png/PngHeader.cs
index d54050e029..da747a1897 100644
--- a/src/ImageSharp/Formats/Png/PngHeader.cs
+++ b/src/ImageSharp/Formats/Png/PngHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
index d2ce98847a..d8bcbac0f2 100644
--- a/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
index 9f97c2e4e2..4e6c2bbd00 100644
--- a/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
+++ b/src/ImageSharp/Formats/Png/PngInterlaceMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Png/PngMetadata.cs b/src/ImageSharp/Formats/Png/PngMetadata.cs
index 185e7bf4aa..52d70906dc 100644
--- a/src/ImageSharp/Formats/Png/PngMetadata.cs
+++ b/src/ImageSharp/Formats/Png/PngMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
using SixLabors.ImageSharp.PixelFormats;
diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
index 26bc566d65..41b5c370d7 100644
--- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
+++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers.Binary;
diff --git a/src/ImageSharp/Formats/Png/PngTextData.cs b/src/ImageSharp/Formats/Png/PngTextData.cs
index 6c391d62a3..3d495cba6e 100644
--- a/src/ImageSharp/Formats/Png/PngTextData.cs
+++ b/src/ImageSharp/Formats/Png/PngTextData.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Png/PngThrowHelper.cs b/src/ImageSharp/Formats/Png/PngThrowHelper.cs
index ae7d16ec71..7cf954f1d6 100644
--- a/src/ImageSharp/Formats/Png/PngThrowHelper.cs
+++ b/src/ImageSharp/Formats/Png/PngThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs b/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs
index fe92e7fbf6..4505787cce 100644
--- a/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs
+++ b/src/ImageSharp/Formats/Png/PngTransparentColorMode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Png
{
diff --git a/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs b/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
index 240b8b9b3a..d2d0944a2c 100644
--- a/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
+++ b/src/ImageSharp/Formats/Tga/ITgaDecoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs b/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
index 21599902a2..a6fd215db5 100644
--- a/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Tga/ITgaEncoderOptions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/MetadataExtensions.cs b/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
index 00bdb01880..2f085af73c 100644
--- a/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
+++ b/src/ImageSharp/Formats/Tga/MetadataExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.Metadata;
diff --git a/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs b/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
index 7c04ed4d8b..1e5083ce5f 100644
--- a/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
+++ b/src/ImageSharp/Formats/Tga/TgaBitsPerPixel.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaCompression.cs b/src/ImageSharp/Formats/Tga/TgaCompression.cs
index 526d3b3e52..fc9601a48f 100644
--- a/src/ImageSharp/Formats/Tga/TgaCompression.cs
+++ b/src/ImageSharp/Formats/Tga/TgaCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs b/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
index eecd5f0ea4..6ea273fb44 100644
--- a/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
+++ b/src/ImageSharp/Formats/Tga/TgaConfigurationModule.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaConstants.cs b/src/ImageSharp/Formats/Tga/TgaConstants.cs
index 990c2bcb10..2dd8c3e808 100644
--- a/src/ImageSharp/Formats/Tga/TgaConstants.cs
+++ b/src/ImageSharp/Formats/Tga/TgaConstants.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoder.cs b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
index bb0a0d5489..a256850e6a 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoder.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
index d101ccd94a..af586e2544 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
///
/// Gets the dimensions of the image.
///
- public Size Dimensions => new Size(this.fileHeader.Width, this.fileHeader.Height);
+ public Size Dimensions => new(this.fileHeader.Width, this.fileHeader.Height);
///
public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken)
@@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.currentStream.Skip(this.fileHeader.IdLength);
// Parse the color map, if present.
- if (this.fileHeader.ColorMapType != 0 && this.fileHeader.ColorMapType != 1)
+ if (this.fileHeader.ColorMapType is not 0 and not 1)
{
TgaThrowHelper.ThrowNotSupportedException($"Unknown tga colormap type {this.fileHeader.ColorMapType} found");
}
@@ -117,7 +117,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
using (IMemoryOwner palette = this.memoryAllocator.Allocate(colorMapSizeInBytes, AllocationOptions.Clean))
{
Span paletteSpan = palette.GetSpan();
- this.currentStream.Read(paletteSpan, this.fileHeader.CMapStart, colorMapSizeInBytes);
+ int bytesRead = this.currentStream.Read(paletteSpan, this.fileHeader.CMapStart, colorMapSizeInBytes);
+ if (bytesRead != colorMapSizeInBytes)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read the color map");
+ }
if (this.fileHeader.ImageType == TgaImageType.RleColorMapped)
{
@@ -308,8 +312,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadPalettedRle(int width, int height, Buffer2D pixels, Span palette, int colorMapPixelSizeInBytes, TgaImageOrigin origin)
where TPixel : unmanaged, IPixel
{
- int bytesPerPixel = 1;
- using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height * bytesPerPixel, AllocationOptions.Clean))
+ using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height, AllocationOptions.Clean))
{
TPixel color = default;
Span bufferSpan = buffer.GetSpan();
@@ -319,7 +322,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
int newY = InvertY(y, height, origin);
Span pixelRow = pixels.DangerousGetRowSpan(newY);
- int rowStartIdx = y * width * bytesPerPixel;
+ int rowStartIdx = y * width;
for (int x = 0; x < width; x++)
{
int idx = rowStartIdx + x;
@@ -418,7 +421,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
for (int x = width - 1; x >= 0; x--)
{
- this.currentStream.Read(this.scratchBuffer, 0, 2);
+ int bytesRead = this.currentStream.Read(this.scratchBuffer, 0, 2);
+ if (bytesRead != 2)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row");
+ }
+
if (!this.hasAlpha)
{
this.scratchBuffer[1] |= 1 << 7;
@@ -438,7 +446,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
}
else
{
- this.currentStream.Read(rowSpan);
+ int bytesRead = this.currentStream.Read(rowSpan);
+ if (bytesRead != rowSpan.Length)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row");
+ }
if (!this.hasAlpha)
{
@@ -579,7 +591,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel
{
TPixel color = default;
- var alphaBits = this.tgaMetadata.AlphaChannelBits;
+ byte alphaBits = this.tgaMetadata.AlphaChannelBits;
using (IMemoryOwner buffer = this.memoryAllocator.Allocate(width * height * bytesPerPixel, AllocationOptions.Clean))
{
Span bufferSpan = buffer.GetSpan();
@@ -624,8 +636,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
}
else
{
- var alpha = alphaBits == 0 ? byte.MaxValue : bufferSpan[idx + 3];
- color.FromBgra32(new Bgra32(bufferSpan[idx + 2], bufferSpan[idx + 1], bufferSpan[idx], (byte)alpha));
+ byte alpha = alphaBits == 0 ? byte.MaxValue : bufferSpan[idx + 3];
+ color.FromBgra32(new Bgra32(bufferSpan[idx + 2], bufferSpan[idx + 1], bufferSpan[idx], alpha));
}
break;
@@ -653,7 +665,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadL8Row(int width, Buffer2D pixels, Span row, int y)
where TPixel : unmanaged, IPixel
{
- this.currentStream.Read(row);
+ int bytesRead = this.currentStream.Read(row);
+ if (bytesRead != row.Length)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row");
+ }
+
Span pixelSpan = pixels.DangerousGetRowSpan(y);
PixelOperations.Instance.FromL8Bytes(this.Configuration, row, pixelSpan, width);
}
@@ -662,7 +679,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadL8Pixel(TPixel color, int x, Span pixelSpan)
where TPixel : unmanaged, IPixel
{
- var pixelValue = (byte)this.currentStream.ReadByte();
+ byte pixelValue = (byte)this.currentStream.ReadByte();
color.FromL8(Unsafe.As(ref pixelValue));
pixelSpan[x] = color;
}
@@ -671,7 +688,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadBgr24Pixel(TPixel color, int x, Span pixelSpan)
where TPixel : unmanaged, IPixel
{
- this.currentStream.Read(this.scratchBuffer, 0, 3);
+ int bytesRead = this.currentStream.Read(this.scratchBuffer, 0, 3);
+ if (bytesRead != 3)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a bgr pixel");
+ }
+
color.FromBgr24(Unsafe.As(ref this.scratchBuffer[0]));
pixelSpan[x] = color;
}
@@ -680,7 +702,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadBgr24Row(int width, Buffer2D pixels, Span row, int y)
where TPixel : unmanaged, IPixel
{
- this.currentStream.Read(row);
+ int bytesRead = this.currentStream.Read(row);
+ if (bytesRead != row.Length)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row");
+ }
+
Span pixelSpan = pixels.DangerousGetRowSpan(y);
PixelOperations.Instance.FromBgr24Bytes(this.Configuration, row, pixelSpan, width);
}
@@ -689,8 +716,13 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadBgra32Pixel(int x, TPixel color, Span pixelRow)
where TPixel : unmanaged, IPixel
{
- this.currentStream.Read(this.scratchBuffer, 0, 4);
- var alpha = this.tgaMetadata.AlphaChannelBits == 0 ? byte.MaxValue : this.scratchBuffer[3];
+ int bytesRead = this.currentStream.Read(this.scratchBuffer, 0, 4);
+ if (bytesRead != 4)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a bgra pixel");
+ }
+
+ byte alpha = this.tgaMetadata.AlphaChannelBits == 0 ? byte.MaxValue : this.scratchBuffer[3];
color.FromBgra32(new Bgra32(this.scratchBuffer[2], this.scratchBuffer[1], this.scratchBuffer[0], alpha));
pixelRow[x] = color;
}
@@ -699,7 +731,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void ReadBgra32Row(int width, Buffer2D pixels, Span row, int y)
where TPixel : unmanaged, IPixel
{
- this.currentStream.Read(row);
+ int bytesRead = this.currentStream.Read(row);
+ if (bytesRead != row.Length)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel row");
+ }
+
Span pixelSpan = pixels.DangerousGetRowSpan(y);
PixelOperations.Instance.FromBgra32Bytes(this.Configuration, row, pixelSpan, width);
}
@@ -709,6 +746,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel
{
int colorIndex = this.currentStream.ReadByte();
+ if (colorIndex == -1)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read color index");
+ }
+
this.ReadPalettedBgra16Pixel(palette, colorIndex, colorMapPixelSizeInBytes, ref color);
pixelRow[x] = color;
}
@@ -734,6 +776,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel
{
int colorIndex = this.currentStream.ReadByte();
+ if (colorIndex == -1)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read color index");
+ }
+
color.FromBgr24(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
pixelRow[x] = color;
}
@@ -743,6 +790,11 @@ namespace SixLabors.ImageSharp.Formats.Tga
where TPixel : unmanaged, IPixel
{
int colorIndex = this.currentStream.ReadByte();
+ if (colorIndex == -1)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read color index");
+ }
+
color.FromBgra32(Unsafe.As(ref palette[colorIndex * colorMapPixelSizeInBytes]));
pixelRow[x] = color;
}
@@ -757,7 +809,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
private void UncompressRle(int width, int height, Span buffer, int bytesPerPixel)
{
int uncompressedPixels = 0;
- var pixel = new byte[bytesPerPixel];
+ Span pixel = this.scratchBuffer.AsSpan(0, bytesPerPixel);
int totalPixels = width * height;
while (uncompressedPixels < totalPixels)
{
@@ -768,11 +820,16 @@ namespace SixLabors.ImageSharp.Formats.Tga
if (highBit == 1)
{
int runLength = runLengthByte & 127;
- this.currentStream.Read(pixel, 0, bytesPerPixel);
+ int bytesRead = this.currentStream.Read(pixel, 0, bytesPerPixel);
+ if (bytesRead != bytesPerPixel)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel from the stream");
+ }
+
int bufferIdx = uncompressedPixels * bytesPerPixel;
for (int i = 0; i < runLength + 1; i++, uncompressedPixels++)
{
- pixel.AsSpan().CopyTo(buffer.Slice(bufferIdx));
+ pixel.CopyTo(buffer.Slice(bufferIdx));
bufferIdx += bytesPerPixel;
}
}
@@ -783,8 +840,13 @@ namespace SixLabors.ImageSharp.Formats.Tga
int bufferIdx = uncompressedPixels * bytesPerPixel;
for (int i = 0; i < runLength + 1; i++, uncompressedPixels++)
{
- this.currentStream.Read(pixel, 0, bytesPerPixel);
- pixel.AsSpan().CopyTo(buffer.Slice(bufferIdx));
+ int bytesRead = this.currentStream.Read(pixel, 0, bytesPerPixel);
+ if (bytesRead != bytesPerPixel)
+ {
+ TgaThrowHelper.ThrowInvalidImageContentException("Not enough data to read a pixel from the stream");
+ }
+
+ pixel.CopyTo(buffer.Slice(bufferIdx));
bufferIdx += bytesPerPixel;
}
}
@@ -815,17 +877,12 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The image origin.
/// True, if y coordinate needs to be inverted.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool InvertY(TgaImageOrigin origin)
+ private static bool InvertY(TgaImageOrigin origin) => origin switch
{
- switch (origin)
- {
- case TgaImageOrigin.BottomLeft:
- case TgaImageOrigin.BottomRight:
- return true;
- default:
- return false;
- }
- }
+ TgaImageOrigin.BottomLeft => true,
+ TgaImageOrigin.BottomRight => true,
+ _ => false
+ };
///
/// Returns the x- value based on the given width.
@@ -851,17 +908,13 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// The image origin.
/// True, if x coordinate needs to be inverted.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool InvertX(TgaImageOrigin origin)
- {
- switch (origin)
+ private static bool InvertX(TgaImageOrigin origin) =>
+ origin switch
{
- case TgaImageOrigin.TopRight:
- case TgaImageOrigin.BottomRight:
- return true;
- default:
- return false;
- }
- }
+ TgaImageOrigin.TopRight => true,
+ TgaImageOrigin.BottomRight => true,
+ _ => false
+ };
///
/// Reads the tga file header from the stream.
@@ -880,8 +933,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.tgaMetadata = this.metadata.GetTgaMetadata();
this.tgaMetadata.BitsPerPixel = (TgaBitsPerPixel)this.fileHeader.PixelDepth;
- var alphaBits = this.fileHeader.ImageDescriptor & 0xf;
- if (alphaBits != 0 && alphaBits != 1 && alphaBits != 8)
+ int alphaBits = this.fileHeader.ImageDescriptor & 0xf;
+ if (alphaBits is not 0 and not 1 and not 8)
{
TgaThrowHelper.ThrowInvalidImageContentException("Invalid alpha channel bits");
}
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoder.cs b/src/ImageSharp/Formats/Tga/TgaEncoder.cs
index 529d951cd3..e25677ecc5 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoder.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.IO;
using System.Threading;
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
index 1a1260a58e..fa0ea6f90b 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -7,7 +7,6 @@ using System.Buffers.Binary;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
-using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
@@ -73,7 +72,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
this.configuration = image.GetConfiguration();
ImageMetadata metadata = image.Metadata;
TgaMetadata tgaMetadata = metadata.GetTgaMetadata();
- this.bitsPerPixel = this.bitsPerPixel ?? tgaMetadata.BitsPerPixel;
+ this.bitsPerPixel ??= tgaMetadata.BitsPerPixel;
TgaImageType imageType = this.compression is TgaCompression.RunLength ? TgaImageType.RleTrueColor : TgaImageType.TrueColor;
if (this.bitsPerPixel == TgaBitsPerPixel.Pixel8)
@@ -118,7 +117,6 @@ namespace SixLabors.ImageSharp.Formats.Tga
fileHeader.WriteTo(buffer);
stream.Write(buffer, 0, TgaFileHeader.Size);
-
if (this.compression is TgaCompression.RunLength)
{
this.WriteRunLengthEncodedImage(stream, image.Frames.RootFrame);
@@ -160,6 +158,8 @@ namespace SixLabors.ImageSharp.Formats.Tga
case TgaBitsPerPixel.Pixel32:
this.Write32Bit(stream, pixels);
break;
+ default:
+ break;
}
}
@@ -174,91 +174,149 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
Rgba32 color = default;
Buffer2D pixels = image.PixelBuffer;
- int totalPixels = image.Width * image.Height;
- int encodedPixels = 0;
- while (encodedPixels < totalPixels)
+ for (int y = 0; y < image.Height; y++)
{
- int x = encodedPixels % pixels.Width;
- int y = encodedPixels / pixels.Width;
- TPixel currentPixel = pixels[x, y];
- currentPixel.ToRgba32(ref color);
- byte equalPixelCount = this.FindEqualPixels(pixels, x, y);
-
- // Write the number of equal pixels, with the high bit set, indicating ist a compressed pixel run.
- stream.WriteByte((byte)(equalPixelCount | 128));
- switch (this.bitsPerPixel)
+ Span pixelRow = pixels.DangerousGetRowSpan(y);
+ for (int x = 0; x < image.Width;)
{
- case TgaBitsPerPixel.Pixel8:
- int luminance = GetLuminance(currentPixel);
- stream.WriteByte((byte)luminance);
- break;
-
- case TgaBitsPerPixel.Pixel16:
- var bgra5551 = new Bgra5551(color.ToVector4());
- BinaryPrimitives.TryWriteInt16LittleEndian(this.buffer, (short)bgra5551.PackedValue);
- stream.WriteByte(this.buffer[0]);
- stream.WriteByte(this.buffer[1]);
-
- break;
-
- case TgaBitsPerPixel.Pixel24:
- stream.WriteByte(color.B);
- stream.WriteByte(color.G);
- stream.WriteByte(color.R);
- break;
-
- case TgaBitsPerPixel.Pixel32:
- stream.WriteByte(color.B);
- stream.WriteByte(color.G);
- stream.WriteByte(color.R);
- stream.WriteByte(color.A);
- break;
+ TPixel currentPixel = pixelRow[x];
+ currentPixel.ToRgba32(ref color);
+ byte equalPixelCount = this.FindEqualPixels(pixelRow, x);
+
+ if (equalPixelCount > 0)
+ {
+ // Write the number of equal pixels, with the high bit set, indicating ist a compressed pixel run.
+ stream.WriteByte((byte)(equalPixelCount | 128));
+ this.WritePixel(stream, currentPixel, color);
+ x += equalPixelCount + 1;
+ }
+ else
+ {
+ // Write Raw Packet (i.e., Non-Run-Length Encoded):
+ byte unEqualPixelCount = this.FindUnEqualPixels(pixelRow, x);
+ stream.WriteByte(unEqualPixelCount);
+ this.WritePixel(stream, currentPixel, color);
+ x++;
+ for (int i = 0; i < unEqualPixelCount; i++)
+ {
+ currentPixel = pixelRow[x];
+ currentPixel.ToRgba32(ref color);
+ this.WritePixel(stream, currentPixel, color);
+ x++;
+ }
+ }
}
+ }
+ }
+
+ ///
+ /// Writes a the pixel to the stream.
+ ///
+ /// The type of the pixel.
+ /// The stream to write to.
+ /// The current pixel.
+ /// The color of the pixel to write.
+ private void WritePixel(Stream stream, TPixel currentPixel, Rgba32 color)
+ where TPixel : unmanaged, IPixel
+ {
+ switch (this.bitsPerPixel)
+ {
+ case TgaBitsPerPixel.Pixel8:
+ int luminance = GetLuminance(currentPixel);
+ stream.WriteByte((byte)luminance);
+ break;
+
+ case TgaBitsPerPixel.Pixel16:
+ var bgra5551 = new Bgra5551(color.ToVector4());
+ BinaryPrimitives.TryWriteInt16LittleEndian(this.buffer, (short)bgra5551.PackedValue);
+ stream.WriteByte(this.buffer[0]);
+ stream.WriteByte(this.buffer[1]);
+
+ break;
- encodedPixels += equalPixelCount + 1;
+ case TgaBitsPerPixel.Pixel24:
+ stream.WriteByte(color.B);
+ stream.WriteByte(color.G);
+ stream.WriteByte(color.R);
+ break;
+
+ case TgaBitsPerPixel.Pixel32:
+ stream.WriteByte(color.B);
+ stream.WriteByte(color.G);
+ stream.WriteByte(color.R);
+ stream.WriteByte(color.A);
+ break;
+ default:
+ break;
}
}
///
- /// Finds consecutive pixels which have the same value.
+ /// Finds consecutive pixels which have the same value up to 128 pixels maximum.
///
/// The pixel type.
- /// The pixels of the image.
+ /// A pixel row of the image to encode.
/// X coordinate to start searching for the same pixels.
- /// Y coordinate to start searching for the same pixels.
/// The number of equal pixels.
- private byte FindEqualPixels(Buffer2D pixels, int xStart, int yStart)
+ private byte FindEqualPixels(Span pixelRow, int xStart)
where TPixel : unmanaged, IPixel
{
byte equalPixelCount = 0;
- bool firstRow = true;
- TPixel startPixel = pixels[xStart, yStart];
- for (int y = yStart; y < pixels.Height; y++)
+ TPixel startPixel = pixelRow[xStart];
+ for (int x = xStart + 1; x < pixelRow.Length; x++)
{
- for (int x = firstRow ? xStart + 1 : 0; x < pixels.Width; x++)
+ TPixel nextPixel = pixelRow[x];
+ if (startPixel.Equals(nextPixel))
{
- TPixel nextPixel = pixels[x, y];
- if (startPixel.Equals(nextPixel))
- {
- equalPixelCount++;
- }
- else
- {
- return equalPixelCount;
- }
-
- if (equalPixelCount >= 127)
- {
- return equalPixelCount;
- }
+ equalPixelCount++;
+ }
+ else
+ {
+ return equalPixelCount;
}
- firstRow = false;
+ if (equalPixelCount >= 127)
+ {
+ return equalPixelCount;
+ }
}
return equalPixelCount;
}
+ ///
+ /// Finds consecutive pixels which are unequal up to 128 pixels maximum.
+ ///
+ /// The pixel type.
+ /// A pixel row of the image to encode.
+ /// X coordinate to start searching for the unequal pixels.
+ /// The number of equal pixels.
+ private byte FindUnEqualPixels(Span pixelRow, int xStart)
+ where TPixel : unmanaged, IPixel
+ {
+ byte unEqualPixelCount = 0;
+ TPixel currentPixel = pixelRow[xStart];
+ for (int x = xStart + 1; x < pixelRow.Length; x++)
+ {
+ TPixel nextPixel = pixelRow[x];
+ if (currentPixel.Equals(nextPixel))
+ {
+ return unEqualPixelCount;
+ }
+
+ unEqualPixelCount++;
+
+ if (unEqualPixelCount >= 127)
+ {
+ return unEqualPixelCount;
+ }
+
+ currentPixel = nextPixel;
+ }
+
+ return unEqualPixelCount;
+ }
+
private IMemoryOwner AllocateRow(int width, int bytesPerPixel)
=> this.memoryAllocator.AllocatePaddedPixelRowBuffer(width, bytesPerPixel, 0);
diff --git a/src/ImageSharp/Formats/Tga/TgaFileHeader.cs b/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
index 7ea2479dd5..591c218cd1 100644
--- a/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
+++ b/src/ImageSharp/Formats/Tga/TgaFileHeader.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Tga/TgaFormat.cs b/src/ImageSharp/Formats/Tga/TgaFormat.cs
index 9d72ee64ff..6ec70d6555 100644
--- a/src/ImageSharp/Formats/Tga/TgaFormat.cs
+++ b/src/ImageSharp/Formats/Tga/TgaFormat.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Collections.Generic;
diff --git a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
index 018dbc7ca5..a3ecfeb170 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageFormatDetector.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs b/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs
index 43e0a357ba..a31a0f23fa 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageOrigin.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaImageType.cs b/src/ImageSharp/Formats/Tga/TgaImageType.cs
index 9525cc7e78..af9a68f377 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageType.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.
ImageSharp.Formats.Tga
diff --git a/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs b/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
index f323c93ae1..3c0e030c04 100644
--- a/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
+++ b/src/ImageSharp/Formats/Tga/TgaImageTypeExtensions.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaMetadata.cs b/src/ImageSharp/Formats/Tga/TgaMetadata.cs
index 3a86b9551a..a29eac21e4 100644
--- a/src/ImageSharp/Formats/Tga/TgaMetadata.cs
+++ b/src/ImageSharp/Formats/Tga/TgaMetadata.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tga
{
diff --git a/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs b/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
index cf27a56561..4d3e4f28a2 100644
--- a/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
+++ b/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/BitWriterUtils.cs b/src/ImageSharp/Formats/Tiff/Compression/BitWriterUtils.cs
index 08d1475268..1219fa02ed 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/BitWriterUtils.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/BitWriterUtils.cs
@@ -1,22 +1,24 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Tiff.Compression
{
internal static class BitWriterUtils
{
- public static void WriteBits(Span buffer, int pos, uint count, byte value)
+ public static void WriteBits(Span buffer, nint pos, nint count, byte value)
{
- int bitPos = pos % 8;
- int bufferPos = pos / 8;
- int startIdx = bufferPos + bitPos;
- int endIdx = (int)(startIdx + count);
+ nint bitPos = Numerics.Modulo8(pos);
+ nint bufferPos = pos / 8;
+ nint startIdx = bufferPos + bitPos;
+ nint endIdx = startIdx + count;
if (value == 1)
{
- for (int i = startIdx; i < endIdx; i++)
+ for (nint i = startIdx; i < endIdx; i++)
{
WriteBit(buffer, bufferPos, bitPos);
@@ -30,7 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression
}
else
{
- for (int i = startIdx; i < endIdx; i++)
+ for (nint i = startIdx; i < endIdx; i++)
{
WriteZeroBit(buffer, bufferPos, bitPos);
@@ -44,8 +46,18 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression
}
}
- public static void WriteBit(Span buffer, int bufferPos, int bitPos) => buffer[bufferPos] |= (byte)(1 << (7 - bitPos));
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void WriteBit(Span buffer, nint bufferPos, nint bitPos)
+ {
+ ref byte b = ref Unsafe.Add(ref MemoryMarshal.GetReference(buffer), bufferPos);
+ b |= (byte)(1 << (int)(7 - bitPos));
+ }
- public static void WriteZeroBit(Span buffer, int bufferPos, int bitPos) => buffer[bufferPos] = (byte)(buffer[bufferPos] & ~(1 << (7 - bitPos)));
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void WriteZeroBit(Span buffer, nint bufferPos, nint bitPos)
+ {
+ ref byte b = ref Unsafe.Add(ref MemoryMarshal.GetReference(buffer), bufferPos);
+ b = (byte)(b & ~(1 << (int)(7 - bitPos)));
+ }
}
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs
index c240c06ef6..2001228390 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/DeflateCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/LzwCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/LzwCompressor.cs
index d2ae9096e2..0d76187844 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/LzwCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/LzwCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/NoCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/NoCompressor.cs
index 79bb2e98f8..4d2d74ad50 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/NoCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/NoCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsCompressor.cs
index d06aeb1042..01613222e3 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsWriter.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsWriter.cs
index f456324e53..06e2d663c9 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsWriter.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/PackBitsWriter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/T4BitCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/T4BitCompressor.cs
index d038e9c8bf..11bc49f27e 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/T4BitCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/T4BitCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs
index 9e03d2764a..7e0b6042cb 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/T6BitCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs
index 3166106216..511c6914f3 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffCcittCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -23,28 +23,28 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors
64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216, 1280, 1344, 1408, 1472, 1536, 1600, 1664, 1728, 1792, 1856, 1920, 1984, 2048, 2112, 2176, 2240, 2304, 2368, 2432, 2496, 2560
};
- private static readonly Dictionary WhiteLen4TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen4TermCodes = new()
{
{ 2, 0x7 }, { 3, 0x8 }, { 4, 0xB }, { 5, 0xC }, { 6, 0xE }, { 7, 0xF }
};
- private static readonly Dictionary WhiteLen5TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen5TermCodes = new()
{
{ 8, 0x13 }, { 9, 0x14 }, { 10, 0x7 }, { 11, 0x8 }
};
- private static readonly Dictionary WhiteLen6TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen6TermCodes = new()
{
{ 1, 0x7 }, { 12, 0x8 }, { 13, 0x3 }, { 14, 0x34 }, { 15, 0x35 }, { 16, 0x2A }, { 17, 0x2B }
};
- private static readonly Dictionary WhiteLen7TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen7TermCodes = new()
{
{ 18, 0x27 }, { 19, 0xC }, { 20, 0x8 }, { 21, 0x17 }, { 22, 0x3 }, { 23, 0x4 }, { 24, 0x28 }, { 25, 0x2B }, { 26, 0x13 },
{ 27, 0x24 }, { 28, 0x18 }
};
- private static readonly Dictionary WhiteLen8TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen8TermCodes = new()
{
{ 0, WhiteZeroRunTermCode }, { 29, 0x2 }, { 30, 0x3 }, { 31, 0x1A }, { 32, 0x1B }, { 33, 0x12 }, { 34, 0x13 }, { 35, 0x14 },
{ 36, 0x15 }, { 37, 0x16 }, { 38, 0x17 }, { 39, 0x28 }, { 40, 0x29 }, { 41, 0x2A }, { 42, 0x2B }, { 43, 0x2C }, { 44, 0x2D },
@@ -53,57 +53,57 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors
{ 63, 0x34 }
};
- private static readonly Dictionary BlackLen2TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen2TermCodes = new()
{
{ 2, 0x3 }, { 3, 0x2 }
};
- private static readonly Dictionary BlackLen3TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen3TermCodes = new()
{
{ 1, 0x2 }, { 4, 0x3 }
};
- private static readonly Dictionary BlackLen4TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen4TermCodes = new()
{
{ 5, 0x3 }, { 6, 0x2 }
};
- private static readonly Dictionary BlackLen5TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen5TermCodes = new()
{
{ 7, 0x3 }
};
- private static readonly Dictionary BlackLen6TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen6TermCodes = new()
{
{ 8, 0x5 }, { 9, 0x4 }
};
- private static readonly Dictionary BlackLen7TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen7TermCodes = new()
{
{ 10, 0x4 }, { 11, 0x5 }, { 12, 0x7 }
};
- private static readonly Dictionary BlackLen8TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen8TermCodes = new()
{
{ 13, 0x4 }, { 14, 0x7 }
};
- private static readonly Dictionary BlackLen9TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen9TermCodes = new()
{
{ 15, 0x18 }
};
- private static readonly Dictionary BlackLen10TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen10TermCodes = new()
{
{ 0, BlackZeroRunTermCode }, { 16, 0x17 }, { 17, 0x18 }, { 18, 0x8 }
};
- private static readonly Dictionary BlackLen11TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen11TermCodes = new()
{
{ 19, 0x67 }, { 20, 0x68 }, { 21, 0x6C }, { 22, 0x37 }, { 23, 0x28 }, { 24, 0x17 }, { 25, 0x18 }
};
- private static readonly Dictionary BlackLen12TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen12TermCodes = new()
{
{ 26, 0xCA }, { 27, 0xCB }, { 28, 0xCC }, { 29, 0xCD }, { 30, 0x68 }, { 31, 0x69 }, { 32, 0x6A }, { 33, 0x6B }, { 34, 0xD2 },
{ 35, 0xD3 }, { 36, 0xD4 }, { 37, 0xD5 }, { 38, 0xD6 }, { 39, 0xD7 }, { 40, 0x6C }, { 41, 0x6D }, { 42, 0xDA }, { 43, 0xDB },
@@ -112,62 +112,62 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors
{ 62, 0x66 }, { 63, 0x67 }
};
- private static readonly Dictionary WhiteLen5MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen5MakeupCodes = new()
{
{ 64, 0x1B }, { 128, 0x12 }
};
- private static readonly Dictionary WhiteLen6MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen6MakeupCodes = new()
{
{ 192, 0x17 }, { 1664, 0x18 }
};
- private static readonly Dictionary WhiteLen8MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen8MakeupCodes = new()
{
{ 320, 0x36 }, { 384, 0x37 }, { 448, 0x64 }, { 512, 0x65 }, { 576, 0x68 }, { 640, 0x67 }
};
- private static readonly Dictionary WhiteLen7MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen7MakeupCodes = new()
{
{ 256, 0x37 }
};
- private static readonly Dictionary WhiteLen9MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen9MakeupCodes = new()
{
{ 704, 0xCC }, { 768, 0xCD }, { 832, 0xD2 }, { 896, 0xD3 }, { 960, 0xD4 }, { 1024, 0xD5 }, { 1088, 0xD6 },
{ 1152, 0xD7 }, { 1216, 0xD8 }, { 1280, 0xD9 }, { 1344, 0xDA }, { 1408, 0xDB }, { 1472, 0x98 }, { 1536, 0x99 },
{ 1600, 0x9A }, { 1728, 0x9B }
};
- private static readonly Dictionary WhiteLen11MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen11MakeupCodes = new()
{
{ 1792, 0x8 }, { 1856, 0xC }, { 1920, 0xD }
};
- private static readonly Dictionary WhiteLen12MakeupCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen12MakeupCodes = new()
{
{ 1984, 0x12 }, { 2048, 0x13 }, { 2112, 0x14 }, { 2176, 0x15 }, { 2240, 0x16 }, { 2304, 0x17 }, { 2368, 0x1C },
{ 2432, 0x1D }, { 2496, 0x1E }, { 2560, 0x1F }
};
- private static readonly Dictionary BlackLen10MakeupCodes = new Dictionary()
+ private static readonly Dictionary BlackLen10MakeupCodes = new()
{
{ 64, 0xF }
};
- private static readonly Dictionary BlackLen11MakeupCodes = new Dictionary()
+ private static readonly Dictionary BlackLen11MakeupCodes = new()
{
{ 1792, 0x8 }, { 1856, 0xC }, { 1920, 0xD }
};
- private static readonly Dictionary BlackLen12MakeupCodes = new Dictionary()
+ private static readonly Dictionary BlackLen12MakeupCodes = new()
{
{ 128, 0xC8 }, { 192, 0xC9 }, { 256, 0x5B }, { 320, 0x33 }, { 384, 0x34 }, { 448, 0x35 },
{ 1984, 0x12 }, { 2048, 0x13 }, { 2112, 0x14 }, { 2176, 0x15 }, { 2240, 0x16 }, { 2304, 0x17 }, { 2368, 0x1C },
{ 2432, 0x1D }, { 2496, 0x1E }, { 2560, 0x1F }
};
- private static readonly Dictionary BlackLen13MakeupCodes = new Dictionary()
+ private static readonly Dictionary BlackLen13MakeupCodes = new()
{
{ 512, 0x6C }, { 576, 0x6D }, { 640, 0x4A }, { 704, 0x4B }, { 768, 0x4C }, { 832, 0x4D }, { 896, 0x72 },
{ 960, 0x73 }, { 1024, 0x74 }, { 1088, 0x75 }, { 1152, 0x76 }, { 1216, 0x77 }, { 1280, 0x52 }, { 1344, 0x53 },
@@ -442,16 +442,16 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors
}
///
- /// Pads output to the next byte
+ /// Pads output to the next byte.
///
///
/// If the output is not currently on a byte boundary,
- /// zero-pad it to the next byte
+ /// zero-pad it to the next byte.
///
protected void PadByte()
{
// Check if padding is necessary.
- if (this.bitPosition % 8 != 0)
+ if (Numerics.Modulo8(this.bitPosition) != 0)
{
// Skip padding bits, move to next byte.
this.bytePosition++;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffJpegCompressor.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffJpegCompressor.cs
index 231afa3d04..2d20553b3c 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffJpegCompressor.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffJpegCompressor.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffLzwEncoder.cs b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffLzwEncoder.cs
index d4d1d1cb65..69c1f01d3c 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffLzwEncoder.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Compressors/TiffLzwEncoder.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs
index 0aec2361c3..bb2828b912 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs
@@ -1,7 +1,8 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
+using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
@@ -130,6 +131,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
return index + offset;
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private int FindB2ForImaginaryWhiteLine() => this.width;
private int FindB2ForNormalLine(int b1)
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCode.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCode.cs
index 74a17b9075..540b537170 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCode.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCode.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System.Diagnostics;
@@ -13,15 +13,21 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
///
/// Initializes a new instance of the struct.
///
- /// The type.
+ /// The code word.
+ /// The type of the code.
/// The bits required.
/// The extension bits.
- public CcittTwoDimensionalCode(CcittTwoDimensionalCodeType type, int bitsRequired, int extensionBits = 0)
- => this.value = (ushort)((byte)type | ((bitsRequired & 0b1111) << 8) | ((extensionBits & 0b111) << 11));
+ public CcittTwoDimensionalCode(int code, CcittTwoDimensionalCodeType type, int bitsRequired, int extensionBits = 0)
+ {
+ this.Code = code;
+ this.value = (ushort)((byte)type | ((bitsRequired & 0b1111) << 8) | ((extensionBits & 0b111) << 11));
+ }
///
/// Gets the code type.
///
public CcittTwoDimensionalCodeType Type => (CcittTwoDimensionalCodeType)(this.value & 0b11111111);
+
+ public int Code { get; }
}
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCodeType.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCodeType.cs
index 6d5427d638..815415d6b7 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCodeType.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittTwoDimensionalCodeType.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs
index 642cbd3966..37debc9f6f 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/DeflateTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.IO.Compression;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/GrayJpegSpectralConverter.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/GrayJpegSpectralConverter.cs
index 708fbc8458..2a0b8dfc2c 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/GrayJpegSpectralConverter.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/GrayJpegSpectralConverter.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Jpeg.Components;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs
index 88dbcb8828..0d9a6ba139 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Runtime.InteropServices;
@@ -59,30 +59,29 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
case TiffPhotometricInterpretation.BlackIsZero:
case TiffPhotometricInterpretation.WhiteIsZero:
{
- using SpectralConverter spectralConverterGray = new GrayJpegSpectralConverter(this.configuration);
+ using SpectralConverter spectralConverterGray =
+ new GrayJpegSpectralConverter(this.configuration);
var scanDecoderGray = new HuffmanScanDecoder(stream, spectralConverterGray, CancellationToken.None);
jpegDecoder.LoadTables(this.jpegTables, scanDecoderGray);
jpegDecoder.ParseStream(stream, spectralConverterGray, CancellationToken.None);
// TODO: Should we pass through the CancellationToken from the tiff decoder?
- using var decompressedBuffer = spectralConverterGray.GetPixelBuffer(CancellationToken.None);
+ using Buffer2D decompressedBuffer = spectralConverterGray.GetPixelBuffer(CancellationToken.None);
CopyImageBytesToBuffer(buffer, decompressedBuffer);
break;
}
- // If the PhotometricInterpretation is YCbCr we explicitly assume the JPEG data is in RGB color space.
- // There seems no other way to determine that the JPEG data is RGB colorspace (no APP14 marker, componentId's are not RGB).
case TiffPhotometricInterpretation.YCbCr:
case TiffPhotometricInterpretation.Rgb:
{
- using SpectralConverter spectralConverter = this.photometricInterpretation == TiffPhotometricInterpretation.YCbCr ?
- new RgbJpegSpectralConverter(this.configuration) : new SpectralConverter(this.configuration);
+ using SpectralConverter spectralConverter =
+ new TiffJpegSpectralConverter(this.configuration, this.photometricInterpretation);
var scanDecoder = new HuffmanScanDecoder(stream, spectralConverter, CancellationToken.None);
jpegDecoder.LoadTables(this.jpegTables, scanDecoder);
jpegDecoder.ParseStream(stream, spectralConverter, CancellationToken.None);
// TODO: Should we pass through the CancellationToken from the tiff decoder?
- using var decompressedBuffer = spectralConverter.GetPixelBuffer(CancellationToken.None);
+ using Buffer2D decompressedBuffer = spectralConverter.GetPixelBuffer(CancellationToken.None);
CopyImageBytesToBuffer(buffer, decompressedBuffer);
break;
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwString.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwString.cs
index 0f4fb9c9e2..8537c57e16 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwString.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwString.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwTiffCompression.cs
index b5bf7370e7..57da76f6c7 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/LzwTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanBitReader.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanBitReader.cs
index 89cdf7ea2b..1f27ff1cef 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanBitReader.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanBitReader.cs
@@ -1,9 +1,8 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
-using System.IO;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.IO;
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
@@ -19,14 +18,13 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
/// The compressed input stream.
/// The logical order of bits within a byte.
/// The number of bytes to read from the stream.
- /// The memory allocator.
- public ModifiedHuffmanBitReader(Stream input, TiffFillOrder fillOrder, int bytesToRead, MemoryAllocator allocator)
- : base(input, fillOrder, bytesToRead, allocator)
+ public ModifiedHuffmanBitReader(BufferedReadStream input, TiffFillOrder fillOrder, int bytesToRead)
+ : base(input, fillOrder, bytesToRead)
{
}
///
- public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || ((uint)(this.BitsRead - 1) < (7 - 1));
+ public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || (uint)(this.BitsRead - 1) < 6;
///
public override bool IsEndOfScanLine
@@ -53,12 +51,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
base.StartNewRow();
- int remainder = this.BitsRead & 7; // bit-hack for % 8
+ int remainder = Numerics.Modulo8(this.BitsRead);
if (remainder != 0)
{
// Skip padding bits, move to next byte.
- this.Position++;
- this.ResetBitsRead();
+ this.AdvancePosition();
}
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanTiffCompression.cs
index 453f7d10dd..16d3f125bd 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
@@ -42,11 +42,12 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
///
protected override void Decompress(BufferedReadStream stream, int byteCount, int stripHeight, Span buffer)
{
- using var bitReader = new ModifiedHuffmanBitReader(stream, this.FillOrder, byteCount, this.Allocator);
+ var bitReader = new ModifiedHuffmanBitReader(stream, this.FillOrder, byteCount);
buffer.Clear();
- uint bitsWritten = 0;
- uint pixelsWritten = 0;
+ nint bitsWritten = 0;
+ nuint pixelsWritten = 0;
+ nint rowsWritten = 0;
while (bitReader.HasMoreData)
{
bitReader.ReadNextRun();
@@ -55,32 +56,39 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
if (bitReader.IsWhiteRun)
{
- BitWriterUtils.WriteBits(buffer, (int)bitsWritten, bitReader.RunLength, this.whiteValue);
+ BitWriterUtils.WriteBits(buffer, bitsWritten, (int)bitReader.RunLength, this.whiteValue);
}
else
{
- BitWriterUtils.WriteBits(buffer, (int)bitsWritten, bitReader.RunLength, this.blackValue);
+ BitWriterUtils.WriteBits(buffer, bitsWritten, (int)bitReader.RunLength, this.blackValue);
}
- bitsWritten += bitReader.RunLength;
+ bitsWritten += (int)bitReader.RunLength;
pixelsWritten += bitReader.RunLength;
}
- if (pixelsWritten == this.Width)
+ if (pixelsWritten == (ulong)this.Width)
{
- bitReader.StartNewRow();
+ rowsWritten++;
pixelsWritten = 0;
// Write padding bits, if necessary.
- uint pad = 8 - (bitsWritten % 8);
+ nint pad = 8 - Numerics.Modulo8(bitsWritten);
if (pad != 8)
{
- BitWriterUtils.WriteBits(buffer, (int)bitsWritten, pad, 0);
+ BitWriterUtils.WriteBits(buffer, bitsWritten, pad, 0);
bitsWritten += pad;
}
+
+ if (rowsWritten >= stripHeight)
+ {
+ break;
+ }
+
+ bitReader.StartNewRow();
}
- if (pixelsWritten > this.Width)
+ if (pixelsWritten > (ulong)this.Width)
{
TiffThrowHelper.ThrowImageFormatException("ccitt compression parsing error, decoded more pixels then image width");
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/NoneTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/NoneTiffCompression.cs
index d016fd3a13..291d40c859 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/NoneTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/NoneTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using SixLabors.ImageSharp.IO;
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/PackBitsTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/PackBitsTiffCompression.cs
index 4093d89871..9df331b6ea 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/PackBitsTiffCompression.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/PackBitsTiffCompression.cs
@@ -1,5 +1,5 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
using System;
using System.Buffers;
@@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
byte repeatData = compressedData[compressedOffset + 1];
int repeatLength = 257 - headerByte;
- ArrayCopyRepeat(repeatData, buffer, decompressedOffset, repeatLength);
+ buffer.Slice(decompressedOffset, repeatLength).Fill(repeatData);
compressedOffset += 2;
decompressedOffset += repeatLength;
@@ -81,14 +81,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
}
}
- private static void ArrayCopyRepeat(byte value, Span destinationArray, int destinationIndex, int length)
- {
- for (int i = 0; i < length; i++)
- {
- destinationArray[i + destinationIndex] = value;
- }
- }
-
///
protected override void Dispose(bool disposing) => this.compressedDataMemory?.Dispose();
}
diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs
index 9925d5a194..02756d807b 100644
--- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs
+++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs
@@ -1,20 +1,17 @@
// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
+// Licensed under the Six Labors Split License.
-using System;
-using System.Buffers;
using System.Collections.Generic;
-using System.IO;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Tiff.Constants;
-using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.IO;
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{
///
/// Bitreader for reading compressed CCITT T4 1D data.
///
- internal class T4BitReader : IDisposable
+ internal class T4BitReader
{
///
/// The logical order of bits within a byte.
@@ -52,28 +49,28 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
///
private readonly int maxCodeLength = 13;
- private static readonly Dictionary WhiteLen4TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen4TermCodes = new()
{
{ 0x7, 2 }, { 0x8, 3 }, { 0xB, 4 }, { 0xC, 5 }, { 0xE, 6 }, { 0xF, 7 }
};
- private static readonly Dictionary WhiteLen5TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen5TermCodes = new()
{
{ 0x13, 8 }, { 0x14, 9 }, { 0x7, 10 }, { 0x8, 11 }
};
- private static readonly Dictionary WhiteLen6TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen6TermCodes = new()
{
{ 0x7, 1 }, { 0x8, 12 }, { 0x3, 13 }, { 0x34, 14 }, { 0x35, 15 }, { 0x2A, 16 }, { 0x2B, 17 }
};
- private static readonly Dictionary WhiteLen7TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen7TermCodes = new()
{
{ 0x27, 18 }, { 0xC, 19 }, { 0x8, 20 }, { 0x17, 21 }, { 0x3, 22 }, { 0x4, 23 }, { 0x28, 24 }, { 0x2B, 25 }, { 0x13, 26 },
{ 0x24, 27 }, { 0x18, 28 }
};
- private static readonly Dictionary WhiteLen8TermCodes = new Dictionary()
+ private static readonly Dictionary WhiteLen8TermCodes = new()
{
{ 0x35, 0 }, { 0x2, 29 }, { 0x3, 30 }, { 0x1A, 31 }, { 0x1B, 32 }, { 0x12, 33 }, { 0x13, 34 }, { 0x14, 35 }, { 0x15, 36 },
{ 0x16, 37 }, { 0x17, 38 }, { 0x28, 39 }, { 0x29, 40 }, { 0x2A, 41 }, { 0x2B, 42 }, { 0x2C, 43 }, { 0x2D, 44 }, { 0x4, 45 },
@@ -81,57 +78,57 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{ 0x58, 55 }, { 0x59, 56 }, { 0x5A, 57 }, { 0x5B, 58 }, { 0x4A, 59 }, { 0x4B, 60 }, { 0x32, 61 }, { 0x33, 62 }, { 0x34, 63 }
};
- private static readonly Dictionary BlackLen2TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen2TermCodes = new()
{
{ 0x3, 2 }, { 0x2, 3 }
};
- private static readonly Dictionary BlackLen3TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen3TermCodes = new()
{
{ 0x2, 1 }, { 0x3, 4 }
};
- private static readonly Dictionary BlackLen4TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen4TermCodes = new()
{
{ 0x3, 5 }, { 0x2, 6 }
};
- private static readonly Dictionary BlackLen5TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen5TermCodes = new()
{
{ 0x3, 7 }
};
- private static readonly Dictionary BlackLen6TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen6TermCodes = new()
{
{ 0x5, 8 }, { 0x4, 9 }
};
- private static readonly Dictionary BlackLen7TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen7TermCodes = new()
{
{ 0x4, 10 }, { 0x5, 11 }, { 0x7, 12 }
};
- private static readonly Dictionary BlackLen8TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen8TermCodes = new()
{
{ 0x4, 13 }, { 0x7, 14 }
};
- private static readonly Dictionary BlackLen9TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen9TermCodes = new()
{
{ 0x18, 15 }
};
- private static readonly Dictionary BlackLen10TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen10TermCodes = new()
{
{ 0x37, 0 }, { 0x17, 16 }, { 0x18, 17 }, { 0x8, 18 }
};
- private static readonly Dictionary BlackLen11TermCodes = new Dictionary()
+ private static readonly Dictionary BlackLen11TermCodes = new()
{
{ 0x67, 19 }, { 0x68, 20 }, { 0x6C, 21 }, { 0x37, 22 }, { 0x28, 23 }, { 0x17, 24 }, { 0x18, 25 }
};
- private static readonly Dictionary BlackLen12TermCodes = new Dictionary()
+ private static readonly Dictionary