Skip to content

Commit 984c891

Browse files
Merge pull request #106 from iron-software/releases/2024.6
Releases 2024.6 [master]
2 parents 3e204ca + e863e40 commit 984c891

8 files changed

Lines changed: 136 additions & 55 deletions

File tree

CI/job_templates/test_drawing_libraries.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ jobs:
3232
inputs:
3333
packageType: 'sdk'
3434
version: '5.x'
35+
# .NET 7.0 need to install only on x86
36+
- ${{ if and(eq(parameters.framework, 'net70'), eq(parameters.architecture, '.x86')) }}:
37+
- task: UseDotNet@2
38+
displayName: 'Install .NET7 sdk'
39+
inputs:
40+
packageType: 'sdk'
41+
version: '7.x'
42+
env:
43+
PROCESSOR_ARCHITECTURE: x86
3544
- ${{ if ne(parameters.framework, 'net60') }}:
3645
- task: DotNetCoreCLI@2
3746
displayName: Execute ${{ parameters.OSPlatform }} ${{ parameters.framework}} ${{ parameters.architecture }} Tests

CI/stage_templates/run_tests_on_pool.yml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,71 @@ stages:
1616
- script: echo "Skip Unit tests"
1717
- ${{ if eq(parameters.runUnitTests, true) }}:
1818
- ${{ if eq(parameters.OSPlatform, 'Windows') }}:
19+
# Windows .NET 472 x86 Tests
20+
- template: ../job_templates/test_drawing_libraries.yml
21+
parameters:
22+
name: UnitTest${{ parameters.OSPlatform }}net472x86
23+
OSPlatform: ${{ parameters.OSPlatform }}
24+
framework: 'net472'
25+
architecture: '.x86'
26+
buildConfiguration: $(Configuration)
1927
# Windows .NET 472 x64 Tests
2028
- template: ../job_templates/test_drawing_libraries.yml
2129
parameters:
22-
name: UnitTest${{ parameters.OSPlatform }}net472
30+
name: UnitTest${{ parameters.OSPlatform }}net472x64
2331
OSPlatform: ${{ parameters.OSPlatform }}
2432
framework: 'net472'
2533
architecture: ''
2634
buildConfiguration: $(Configuration)
27-
# Windows .NET Core x64 Tests
28-
- template: ../job_templates/test_drawing_libraries.yml
29-
parameters:
30-
name: UnitTest${{ parameters.OSPlatform }}netcore
31-
OSPlatform: ${{ parameters.OSPlatform }}
32-
framework: 'netcoreapp3.1'
33-
architecture: ''
34-
buildConfiguration: $(Configuration)
35-
# Windows .NET Core x86 Tests
36-
- template: ../job_templates/test_drawing_libraries.yml
37-
parameters:
38-
name: UnitTest${{ parameters.OSPlatform }}netcorex86
39-
OSPlatform: ${{ parameters.OSPlatform }}
40-
framework: 'netcoreapp3.1'
41-
architecture: '.x86'
42-
buildConfiguration: $(Configuration)
43-
# Windows .NET 5.0 Tests
35+
# Windows .NET Core x64 Tests
36+
- template: ../job_templates/test_drawing_libraries.yml
37+
parameters:
38+
name: UnitTest${{ parameters.OSPlatform }}netcore
39+
OSPlatform: ${{ parameters.OSPlatform }}
40+
framework: 'netcoreapp3.1'
41+
architecture: ''
42+
buildConfiguration: $(Configuration)
43+
# Windows .NET Core x86 Tests
44+
- template: ../job_templates/test_drawing_libraries.yml
45+
parameters:
46+
name: UnitTest${{ parameters.OSPlatform }}netcorex86
47+
OSPlatform: ${{ parameters.OSPlatform }}
48+
framework: 'netcoreapp3.1'
49+
architecture: '.x86'
50+
buildConfiguration: $(Configuration)
51+
# Windows .NET 6.0 x86 Tests
52+
- template: ../job_templates/test_drawing_libraries.yml
53+
parameters:
54+
name: UnitTest${{ parameters.OSPlatform }}net60x86
55+
OSPlatform: ${{ parameters.OSPlatform }}
56+
framework: 'net60'
57+
architecture: '.x86'
58+
buildConfiguration: $(Configuration)
59+
# Windows .NET 7.0 x86 Tests
60+
- template: ../job_templates/test_drawing_libraries.yml
61+
parameters:
62+
name: UnitTest${{ parameters.OSPlatform }}net70x86
63+
OSPlatform: ${{ parameters.OSPlatform }}
64+
framework: 'net70'
65+
architecture: '.x86'
66+
buildConfiguration: $(Configuration)
67+
# .NET 5.0 Tests
4468
- template: ../job_templates/test_drawing_libraries.yml
4569
parameters:
4670
name: UnitTest${{ parameters.OSPlatform }}net50
4771
OSPlatform: ${{ parameters.OSPlatform }}
4872
framework: 'net50'
4973
architecture: ''
5074
buildConfiguration: $(Configuration)
51-
# Windows .NET 6.0 Tests
75+
# .NET 6.0 x64 Tests
5276
- template: ../job_templates/test_drawing_libraries.yml
5377
parameters:
5478
name: UnitTest${{ parameters.OSPlatform }}net60
5579
OSPlatform: ${{ parameters.OSPlatform }}
5680
framework: 'net60'
5781
architecture: ''
5882
buildConfiguration: $(Configuration)
59-
# Windows .NET 7.0 Tests
83+
# .NET 7.0 x64 Tests
6084
- template: ../job_templates/test_drawing_libraries.yml
6185
parameters:
6286
name: UnitTest${{ parameters.OSPlatform }}net70
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IronSoftware.Drawing.Common.Tests/Data/RenderedFromChrome.bmp filter=lfs diff=lfs merge=lfs -text
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:02c9d5fb29cd2882a4da202ac4f5657a2d3b18df0b2c587d9d545099a9ad7b6f
3+
size 139141366

IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,5 +866,21 @@ public void LoadImage_TiffImage_ShouldLoadWithoutThumbnail()
866866
bitmap.FrameCount.Should().Be(1);
867867
}
868868

869+
870+
[FactWithAutomaticDisplayName]
871+
public void CastAnyBitmap_from_SixLabors()
872+
{
873+
//This test throw System.OutOfMemoryException in x86
874+
875+
var image = Image.Load(GetRelativeFilePath("RenderedFromChrome.bmp"));
876+
877+
var anyBitmap = (AnyBitmap)image;
878+
879+
image.Save("expected.bmp");
880+
anyBitmap.SaveAs("result.bmp");
881+
882+
AssertLargeImageAreEqual("expected.bmp", "result.bmp", true);
883+
}
884+
869885
}
870886
}

IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/Compare.cs

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using SixLabors.ImageSharp.PixelFormats;
2+
using SixLabors.ImageSharp.Processing;
23
using System;
34
using System.IO;
45
using System.Linq;
@@ -14,43 +15,74 @@ protected Compare(ITestOutputHelper output) : base(output)
1415
{
1516
}
1617

17-
protected static void AssertImageAreEqual(string expectedImagePath, string resultImagePath, bool isCleanAll = false)
18+
protected static void AssertLargeImageAreEqual(string expectedImagePath, string resultImagePath, bool isCleanAll = false)
1819
{
19-
string assertName = "AssertImage.AreEqual";
20+
using SixLabors.ImageSharp.Image<Rgba32> expectedImageSharp = SixLabors.ImageSharp.Image.Load<Rgba32>(expectedImagePath);
21+
using SixLabors.ImageSharp.Image<Rgba32> actualImageSharp = SixLabors.ImageSharp.Image.Load<Rgba32>(resultImagePath);
2022

21-
var expected = AnyBitmap.FromFile(expectedImagePath);
22-
var actual = AnyBitmap.FromFile(resultImagePath);
23+
CleanCompareResultFile(expectedImagePath, resultImagePath, isCleanAll);
2324

24-
if (isCleanAll)
25-
{
26-
CleanResultFile(expectedImagePath);
27-
}
25+
expectedImageSharp.Mutate(x => x.Resize(100, 100));
26+
actualImageSharp.Mutate(x => x.Resize(100, 100));
2827

29-
CleanResultFile(resultImagePath);
28+
AssertImageAreEqual(expectedImageSharp, actualImageSharp);
29+
}
3030

31-
//Test to see if we have the same size of image
32-
if (expected.Width != actual.Width || expected.Height != actual.Height)
33-
{
34-
throw new AssertActualExpectedException($"Expected:<Height {expected.Height}, Width {expected.Width}>.", $"Actual:<Height {actual.Height},Width {actual.Width}>.", $"{assertName} failed.");
35-
}
31+
protected static void AssertImageAreEqual(string expectedImagePath, string resultImagePath, bool isCleanAll = false)
32+
{
33+
using var expected = AnyBitmap.FromFile(expectedImagePath);
34+
using var actual = AnyBitmap.FromFile(resultImagePath);
3635

37-
//Convert each image to a byte array
38-
byte[] btImageExpected = expected.ExportBytes();
39-
byte[] btImageActual = expected.ExportBytes();
36+
CleanCompareResultFile(expectedImagePath, resultImagePath, isCleanAll);
4037

41-
//Compute a hash for each image
42-
var shaM = SHA256.Create();
43-
byte[] hash1 = shaM.ComputeHash(btImageExpected);
44-
byte[] hash2 = shaM.ComputeHash(btImageActual);
38+
AssertImageAreEqual(expected, actual);
39+
}
4540

46-
//Compare the hash values
47-
for (int i = 0; i < hash1.Length && i < hash2.Length; i++)
41+
protected static void AssertImageAreEqual(AnyBitmap expected, AnyBitmap actual)
42+
{
43+
try
4844
{
49-
if (hash1[i] != hash2[i])
45+
string assertName = "AssertImage.AreEqual";
46+
47+
//Test to see if we have the same size of image
48+
if (expected.Width != actual.Width || expected.Height != actual.Height)
5049
{
51-
throw new AssertActualExpectedException($"Expected:<hash value {hash1[i]}>.", $"Actual:<hash value {hash2[i]}>.", $"{assertName} failed.");
50+
throw new AssertActualExpectedException($"Expected:<Height {expected.Height}, Width {expected.Width}>.", $"Actual:<Height {actual.Height},Width {actual.Width}>.", $"{assertName} failed.");
5251
}
52+
53+
//Convert each image to a byte array
54+
byte[] btImageExpected = expected.ExportBytes();
55+
byte[] btImageActual = expected.ExportBytes();
56+
57+
//Compute a hash for each image
58+
var shaM = SHA256.Create();
59+
byte[] hash1 = shaM.ComputeHash(btImageExpected);
60+
byte[] hash2 = shaM.ComputeHash(btImageActual);
61+
62+
//Compare the hash values
63+
for (int i = 0; i < hash1.Length && i < hash2.Length; i++)
64+
{
65+
if (hash1[i] != hash2[i])
66+
{
67+
throw new AssertActualExpectedException($"Expected:<hash value {hash1[i]}>.", $"Actual:<hash value {hash2[i]}>.", $"{assertName} failed.");
68+
}
69+
}
70+
}
71+
finally
72+
{
73+
expected?.Dispose();
74+
actual?.Dispose();
75+
}
76+
}
77+
78+
private static void CleanCompareResultFile(string expectedImagePath, string resultImagePath, bool isCleanAll)
79+
{
80+
if (isCleanAll)
81+
{
82+
CleanResultFile(expectedImagePath);
5383
}
84+
85+
CleanResultFile(resultImagePath);
5486
}
5587

5688
protected static void CleanResultFile(string filename)
@@ -60,6 +92,7 @@ protected static void CleanResultFile(string filename)
6092
File.Delete(filename);
6193
}
6294
}
95+
6396
protected static void AssertStreamAreEqual(MemoryStream expected, MemoryStream actual)
6497
{
6598
string assertName = "AssertStream.AreEqual";

IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public AnyBitmap Clone(Rectangle rectangle)
174174
public byte[] ExportBytes(
175175
ImageFormat format = ImageFormat.Default, int lossy = 100)
176176
{
177-
MemoryStream mem = new();
177+
using MemoryStream mem = new();
178178
ExportStream(mem, format, lossy);
179179
byte[] byteArray = mem.ToArray();
180180

@@ -202,13 +202,7 @@ public void ExportFile(
202202
ImageFormat format = ImageFormat.Default,
203203
int lossy = 100)
204204
{
205-
using (MemoryStream mem = new())
206-
{
207-
ExportStream(mem, format, lossy);
208-
byte[] byteArray = mem.ToArray();
209-
210-
File.WriteAllBytes(file, byteArray);
211-
}
205+
SaveAs(file, format, lossy);
212206
}
213207

214208
/// <summary>
@@ -346,7 +340,8 @@ public void SaveAs(string file)
346340
/// <seealso cref="TrySaveAs(string)"/>
347341
public void SaveAs(string file, ImageFormat format, int lossy = 100)
348342
{
349-
File.WriteAllBytes(file, ExportBytes(format, lossy));
343+
using var fileStream = new FileStream(file, FileMode.Create);
344+
ExportStream(fileStream, format, lossy);
350345
}
351346

352347
/// <summary>

NuGet/IronSoftware.Drawing.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Supports:
3939

4040
For general support and technical inquiries, please email us at: support@ironsoftware.com</description>
4141
<summary>IronSoftware.System.Drawing is an open-source solution for .NET developers to replace System.Drawing.Common with a universal and flexible library.</summary>
42-
<releaseNotes>- Update SixLabors.ImageSharp &amp; SixLabors.ImageSharp.Drawing to address known vulnerabilities.</releaseNotes>
42+
<releaseNotes>- Improves memory management when loading large image input</releaseNotes>
4343
<copyright>Copyright © Iron Software 2022-2024</copyright>
4444
<tags>Images, Bitmap, SkiaSharp, SixLabors, BitMiracle, Maui, SVG, TIFF, TIF, GIF, JPEG, PNG, Color, Rectangle, Drawing, C#, VB.NET, ASPX, create, render, generate, standard, netstandard2.0, core, netcore</tags>
4545
<repository type="git" url="https://github.com/iron-software/IronSoftware.Drawing.Common" commit="$commit$" />

0 commit comments

Comments
 (0)