Skip to content

Commit 743f4e9

Browse files
authored
Merge branch 'master' into bp/tiff-fax4
2 parents 3f4f078 + 36f4ad4 commit 743f4e9

File tree

12 files changed

+188
-89
lines changed

12 files changed

+188
-89
lines changed
Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
name: Build
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
tags:
8-
- "v*"
9-
pull_request:
10-
branches:
11-
- master
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- master
1212
jobs:
1313
Build:
1414
strategy:
1515
matrix:
1616
options:
17+
- os: ubuntu-latest
18+
framework: net6.0
19+
sdk: 6.0.x
20+
sdk-preview: true
21+
runtime: -x64
22+
codecov: false
23+
- os: macos-latest
24+
framework: net6.0
25+
sdk: 6.0.x
26+
sdk-preview: true
27+
runtime: -x64
28+
codecov: false
29+
- os: windows-latest
30+
framework: net6.0
31+
sdk: 6.0.x
32+
sdk-preview: true
33+
runtime: -x64
34+
codecov: false
1735
- os: ubuntu-latest
1836
framework: net5.0
1937
runtime: -x64
@@ -52,98 +70,133 @@ jobs:
5270
codecov: false
5371

5472
runs-on: ${{matrix.options.os}}
55-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
5673

5774
steps:
58-
- uses: actions/checkout@v2
75+
- name: Git Config
76+
shell: bash
77+
run: |
78+
git config --global core.autocrlf false
79+
git config --global core.longpaths true
80+
81+
- name: Git Checkout
82+
uses: actions/checkout@v2
83+
with:
84+
fetch-depth: 0
85+
submodules: recursive
5986

6087
# See https://github.com/actions/checkout/issues/165#issuecomment-657673315
61-
- name: Create LFS file list
88+
- name: Git Create LFS FileList
6289
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
6390

64-
- name: Restore LFS cache
91+
- name: Git Setup LFS Cache
6592
uses: actions/cache@v2
6693
id: lfs-cache
6794
with:
6895
path: .git/lfs
6996
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1
7097

71-
- name: Git LFS Pull
98+
- name: Git Pull LFS
7299
run: git lfs pull
73100

74-
- name: Install NuGet
101+
- name: NuGet Install
75102
uses: NuGet/setup-nuget@v1
76103

77-
- name: Setup Git
78-
shell: bash
79-
run: |
80-
git config --global core.autocrlf false
81-
git config --global core.longpaths true
82-
git fetch --prune --unshallow
83-
git submodule -q update --init --recursive
84-
85-
- name: Setup NuGet Cache
104+
- name: NuGet Setup Cache
86105
uses: actions/cache@v2
87106
id: nuget-cache
88107
with:
89108
path: ~/.nuget
90109
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }}
91110
restore-keys: ${{ runner.os }}-nuget-
92111

93-
- name: Build
112+
- name: DotNet Setup Preview
113+
if: ${{ matrix.options.sdk-preview == true }}
114+
uses: actions/setup-dotnet@v1
115+
with:
116+
dotnet-version: ${{ matrix.options.sdk }}
117+
include-prerelease: true
118+
119+
- name: DotNet Build
120+
if: ${{ matrix.options.sdk-preview != true }}
94121
shell: pwsh
95122
run: ./ci-build.ps1 "${{matrix.options.framework}}"
96123
env:
97124
SIXLABORS_TESTING: True
98125

99-
- name: Test
126+
- name: DotNet Build Preview
127+
if: ${{ matrix.options.sdk-preview == true }}
128+
shell: pwsh
129+
run: ./ci-build.ps1 "${{matrix.options.framework}}"
130+
env:
131+
SIXLABORS_TESTING_PREVIEW: True
132+
133+
- name: DotNet Test
134+
if: ${{ matrix.options.sdk-preview != true }}
100135
shell: pwsh
101136
run: ./ci-test.ps1 "${{matrix.options.os}}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}"
102137
env:
103-
SIXLABORS_TESTING: True
104-
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
138+
SIXLABORS_TESTING: True
139+
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
140+
141+
- name: DotNet Test Preview
142+
if: ${{ matrix.options.sdk-preview == true }}
143+
shell: pwsh
144+
run: ./ci-test.ps1 "${{matrix.options.os}}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}"
145+
env:
146+
SIXLABORS_TESTING_PREVIEW: True
147+
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
105148

106149
- name: Export Failed Output
107150
uses: actions/upload-artifact@v2
108151
if: failure()
109152
with:
110-
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
111-
path: tests/Images/ActualOutput/
153+
name: actual_output_${{ runner.os }}_${{ matrix.options.framework }}${{ matrix.options.runtime }}.zip
154+
path: tests/Images/ActualOutput/
112155

113-
- name: Update Codecov
156+
- name: Codecov Update
114157
uses: codecov/codecov-action@v1
115158
if: matrix.options.codecov == true && startsWith(github.repository, 'SixLabors')
116159
with:
117-
flags: unittests
160+
flags: unittests
118161

119162
Publish:
120163
needs: [Build]
121164

122-
runs-on: windows-latest
165+
runs-on: ubuntu-latest
123166

124167
if: (github.event_name == 'push')
125168

126169
steps:
127-
- uses: actions/checkout@v2
128-
129-
- name: Install NuGet
130-
uses: NuGet/setup-nuget@v1
131-
132-
- name: Setup Git
170+
- name: Git Config
133171
shell: bash
134172
run: |
135173
git config --global core.autocrlf false
136174
git config --global core.longpaths true
137-
git fetch --prune --unshallow
138-
git submodule -q update --init --recursive
139175
140-
- name: Pack
176+
- name: Git Checkout
177+
uses: actions/checkout@v2
178+
with:
179+
fetch-depth: 0
180+
submodules: recursive
181+
182+
- name: NuGet Install
183+
uses: NuGet/setup-nuget@v1
184+
185+
- name: NuGet Setup Cache
186+
uses: actions/cache@v2
187+
id: nuget-cache
188+
with:
189+
path: ~/.nuget
190+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }}
191+
restore-keys: ${{ runner.os }}-nuget-
192+
193+
- name: DotNet Pack
141194
shell: pwsh
142195
run: ./ci-pack.ps1
143196

144-
- name: Publish to MyGet
197+
- name: MyGet Publish
145198
shell: pwsh
146199
run: |
147-
nuget.exe push .\artifacts\*.nupkg ${{secrets.MYGET_TOKEN}} -Source https://www.myget.org/F/sixlabors/api/v2/package
148-
nuget.exe push .\artifacts\*.snupkg ${{secrets.MYGET_TOKEN}} -Source https://www.myget.org/F/sixlabors/api/v3/index.json
200+
dotnet nuget push .\artifacts\*.nupkg -k ${{secrets.MYGET_TOKEN}} -s https://www.myget.org/F/sixlabors/api/v2/package
201+
dotnet nuget push .\artifacts\*.snupkg -k ${{secrets.MYGET_TOKEN}} -s https://www.myget.org/F/sixlabors/api/v3/index.json
149202
# TODO: If github.ref starts with 'refs/tags' then it was tag push and we can optionally push out package to nuget.org

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<!-- Import the shared global .props file -->
1919
<Import Project="$(MSBuildThisFileDirectory)shared-infrastructure\msbuild\props\SixLabors.Global.props" />
2020

21+
<PropertyGroup Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
22+
<!-- Workaround various issues bound to implicit language features. -->
23+
<LangVersion>preview</LangVersion>
24+
</PropertyGroup>
25+
2126
<!--
2227
Ensure all custom build configurations based upon "Release" are optimized.
2328
This is easier than setting each project individually.

src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ public void Dispose()
345345
}
346346

347347
/// <summary>
348-
/// Returns the correct colorspace based on the image component count
348+
/// Returns the correct colorspace based on the image component count and the jpeg frame components.
349349
/// </summary>
350350
/// <returns>The <see cref="JpegColorSpace"/></returns>
351-
private JpegColorSpace DeduceJpegColorSpace(byte componentCount)
351+
private JpegColorSpace DeduceJpegColorSpace(byte componentCount, JpegComponent[] components)
352352
{
353353
if (componentCount == 1)
354354
{
@@ -362,6 +362,12 @@ private JpegColorSpace DeduceJpegColorSpace(byte componentCount)
362362
return JpegColorSpace.RGB;
363363
}
364364

365+
// If the component Id's are R, G, B in ASCII the colorspace is RGB and not YCbCr.
366+
if (components[2].Id == 66 && components[1].Id == 71 && components[0].Id == 82)
367+
{
368+
return JpegColorSpace.RGB;
369+
}
370+
365371
// Some images are poorly encoded and contain incorrect colorspace transform metadata.
366372
// We ignore that and always fall back to the default colorspace.
367373
return JpegColorSpace.YCbCr;
@@ -836,60 +842,60 @@ private void ProcessStartOfFrameMarker(BufferedReadStream stream, int remaining,
836842

837843
// 1 byte: Number of components
838844
byte componentCount = this.temp[5];
839-
this.ColorSpace = this.DeduceJpegColorSpace(componentCount);
840-
841-
this.Metadata.GetJpegMetadata().ColorType = this.ColorSpace == JpegColorSpace.Grayscale ? JpegColorType.Luminance : JpegColorType.YCbCr;
842845

843846
this.Frame = new JpegFrame(frameMarker, precision, frameWidth, frameHeight, componentCount);
844847

845-
if (!metadataOnly)
848+
remaining -= length;
849+
850+
// Validate: remaining part must be equal to components * 3
851+
const int componentBytes = 3;
852+
if (remaining != componentCount * componentBytes)
846853
{
847-
remaining -= length;
854+
JpegThrowHelper.ThrowBadMarker("SOFn", remaining);
855+
}
848856

849-
// Validate: remaining part must be equal to components * 3
850-
const int componentBytes = 3;
851-
if (remaining != componentCount * componentBytes)
852-
{
853-
JpegThrowHelper.ThrowBadMarker("SOFn", remaining);
854-
}
857+
// components*3 bytes: component data
858+
stream.Read(this.temp, 0, remaining);
859+
860+
// No need to pool this. They max out at 4
861+
this.Frame.ComponentIds = new byte[componentCount];
862+
this.Frame.ComponentOrder = new byte[componentCount];
863+
this.Frame.Components = new JpegComponent[componentCount];
855864

856-
// components*3 bytes: component data
857-
stream.Read(this.temp, 0, remaining);
865+
int maxH = 0;
866+
int maxV = 0;
867+
int index = 0;
868+
for (int i = 0; i < componentCount; i++)
869+
{
870+
byte hv = this.temp[index + 1];
871+
int h = (hv >> 4) & 15;
872+
int v = hv & 15;
858873

859-
// No need to pool this. They max out at 4
860-
this.Frame.ComponentIds = new byte[componentCount];
861-
this.Frame.ComponentOrder = new byte[componentCount];
862-
this.Frame.Components = new JpegComponent[componentCount];
874+
if (maxH < h)
875+
{
876+
maxH = h;
877+
}
863878

864-
int maxH = 0;
865-
int maxV = 0;
866-
int index = 0;
867-
for (int i = 0; i < componentCount; i++)
879+
if (maxV < v)
868880
{
869-
byte hv = this.temp[index + 1];
870-
int h = (hv >> 4) & 15;
871-
int v = hv & 15;
881+
maxV = v;
882+
}
872883

873-
if (maxH < h)
874-
{
875-
maxH = h;
876-
}
884+
var component = new JpegComponent(this.Configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i);
877885

878-
if (maxV < v)
879-
{
880-
maxV = v;
881-
}
886+
this.Frame.Components[i] = component;
887+
this.Frame.ComponentIds[i] = component.Id;
882888

883-
var component = new JpegComponent(this.Configuration.MemoryAllocator, this.Frame, this.temp[index], h, v, this.temp[index + 2], i);
889+
index += componentBytes;
890+
}
884891

885-
this.Frame.Components[i] = component;
886-
this.Frame.ComponentIds[i] = component.Id;
892+
this.ColorSpace = this.DeduceJpegColorSpace(componentCount, this.Frame.Components);
887893

888-
index += componentBytes;
889-
}
894+
this.Metadata.GetJpegMetadata().ColorType = this.ColorSpace == JpegColorSpace.Grayscale ? JpegColorType.Luminance : JpegColorType.YCbCr;
890895

896+
if (!metadataOnly)
897+
{
891898
this.Frame.Init(maxH, maxV);
892-
893899
this.scanDecoder.InjectFrameData(this.Frame, this);
894900
}
895901
}

src/ImageSharp/ImageSharp.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
</PropertyGroup>
1717

1818
<Choose>
19+
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
20+
<PropertyGroup>
21+
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>
22+
</PropertyGroup>
23+
</When>
1924
<When Condition="$(SIXLABORS_TESTING) == true">
2025
<PropertyGroup>
2126
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>

src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void CopyPixelRowFast(
257257
[MethodImpl(InliningOptions.ShortMethod)]
258258
private void AddPixelsToHistogram(ref Vector4 greyValuesBase, ref int histogramBase, int luminanceLevels, int length)
259259
{
260-
for (int idx = 0; idx < length; idx++)
260+
for (nint idx = 0; idx < length; idx++)
261261
{
262262
int luminance = ColorNumerics.GetBT709Luminance(ref Unsafe.Add(ref greyValuesBase, idx), luminanceLevels);
263263
Unsafe.Add(ref histogramBase, luminance)++;

tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
<!--Used to hide test project from dotnet test-->
1010
<IsTestProject>false</IsTestProject>
1111
<Configurations>Debug;Release;Debug-InnerLoop;Release-InnerLoop</Configurations>
12-
<LangVersion>9</LangVersion>
1312
<!-- Uncomment this to run benchmarks depending on Colorful or Pfim (colorspaces and TGA): -->
1413
<!--<SignAssembly>false</SignAssembly>-->
1514
</PropertyGroup>
1615

1716
<Choose>
17+
<When Condition="$(SIXLABORS_TESTING_PREVIEW) == true">
18+
<PropertyGroup>
19+
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>
20+
</PropertyGroup>
21+
</When>
1822
<When Condition="$(Configuration.EndsWith('InnerLoop')) == true">
1923
<PropertyGroup>
2024
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>

0 commit comments

Comments
 (0)