Skip to content

Commit 0ad77b8

Browse files
committed
Moved static properties in ColorProfile to a new ColorProfiles class and mark them obsolete.
1 parent c8e7812 commit 0ad77b8

File tree

12 files changed

+138
-84
lines changed

12 files changed

+138
-84
lines changed

src/Magick.NET.Core/Profiles/Color/ColorProfile.cs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Diagnostics.CodeAnalysis;
76
using System.IO;
87

@@ -13,9 +12,6 @@ namespace ImageMagick;
1312
/// </summary>
1413
public sealed class ColorProfile : ImageProfile, IColorProfile
1514
{
16-
private static readonly object _syncRoot = new object();
17-
private static readonly Dictionary<string, ColorProfile> _profiles = [];
18-
1915
private ColorProfileData? _data;
2016

2117
/// <summary>
@@ -59,38 +55,44 @@ public ColorProfile(string name, byte[] data)
5955
/// <summary>
6056
/// Gets the AdobeRGB1998 profile.
6157
/// </summary>
58+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.AdobeRGB1998)} instead.")]
6259
public static ColorProfile AdobeRGB1998
63-
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "AdobeRGB1998.icc");
60+
=> ColorProfiles.AdobeRGB1998;
6461

6562
/// <summary>
6663
/// Gets the AppleRGB profile.
6764
/// </summary>
65+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.AppleRGB)} instead.")]
6866
public static ColorProfile AppleRGB
69-
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "AppleRGB.icc");
67+
=> ColorProfiles.AppleRGB;
7068

7169
/// <summary>
7270
/// Gets the CoatedFOGRA39 profile.
7371
/// </summary>
72+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.CoatedFOGRA39)} instead.")]
7473
public static ColorProfile CoatedFOGRA39
75-
=> Load("ImageMagick.Resources.ColorProfiles.CMYK", "CoatedFOGRA39.icc");
74+
=> ColorProfiles.CoatedFOGRA39;
7675

7776
/// <summary>
7877
/// Gets the ColorMatchRGB profile.
7978
/// </summary>
79+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.ColorMatchRGB)} instead.")]
8080
public static ColorProfile ColorMatchRGB
81-
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "ColorMatchRGB.icc");
81+
=> ColorProfiles.ColorMatchRGB;
8282

8383
/// <summary>
8484
/// Gets the sRGB profile.
8585
/// </summary>
86+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.SRGB)} instead.")]
8687
public static ColorProfile SRGB
87-
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "SRGB.icm");
88+
=> ColorProfiles.SRGB;
8889

8990
/// <summary>
9091
/// Gets the USWebCoatedSWOP profile.
9192
/// </summary>
93+
[Obsolete($"This property will be removed in the next major release. Use {nameof(ColorProfiles)}.{nameof(ColorProfiles.USWebCoatedSWOP)} instead.")]
9294
public static ColorProfile USWebCoatedSWOP
93-
=> Load("ImageMagick.Resources.ColorProfiles.CMYK", "USWebCoatedSWOP.icc");
95+
=> ColorProfiles.USWebCoatedSWOP;
9496

9597
/// <summary>
9698
/// Gets the color space of the profile.
@@ -152,23 +154,6 @@ public string? Model
152154
}
153155
}
154156

155-
private static ColorProfile Load(string resourcePath, string resourceName)
156-
{
157-
if (!_profiles.ContainsKey(resourceName))
158-
{
159-
lock (_syncRoot)
160-
{
161-
if (!_profiles.ContainsKey(resourceName))
162-
{
163-
using var stream = TypeHelper.GetManifestResourceStream(typeof(ColorProfile), resourcePath, resourceName);
164-
_profiles[resourceName] = new ColorProfile(stream);
165-
}
166-
}
167-
}
168-
169-
return _profiles[resourceName];
170-
}
171-
172157
[MemberNotNull(nameof(_data))]
173158
private void Initialize()
174159
=> _data = ColorProfileReader.Read(GetData());
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
6+
7+
namespace ImageMagick;
8+
9+
/// <summary>
10+
/// Class that contains ICM/ICC color profiles.
11+
/// </summary>
12+
public sealed class ColorProfiles
13+
{
14+
private static readonly Dictionary<string, ColorProfile> _profiles = [];
15+
private static readonly object _syncRoot = new object();
16+
17+
/// <summary>
18+
/// Gets the AdobeRGB1998 profile.
19+
/// </summary>
20+
public static ColorProfile AdobeRGB1998
21+
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "AdobeRGB1998.icc");
22+
23+
/// <summary>
24+
/// Gets the AppleRGB profile.
25+
/// </summary>
26+
public static ColorProfile AppleRGB
27+
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "AppleRGB.icc");
28+
29+
/// <summary>
30+
/// Gets the CoatedFOGRA39 profile.
31+
/// </summary>
32+
public static ColorProfile CoatedFOGRA39
33+
=> Load("ImageMagick.Resources.ColorProfiles.CMYK", "CoatedFOGRA39.icc");
34+
35+
/// <summary>
36+
/// Gets the ColorMatchRGB profile.
37+
/// </summary>
38+
public static ColorProfile ColorMatchRGB
39+
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "ColorMatchRGB.icc");
40+
41+
/// <summary>
42+
/// Gets the sRGB profile.
43+
/// </summary>
44+
public static ColorProfile SRGB
45+
=> Load("ImageMagick.Resources.ColorProfiles.RGB", "SRGB.icm");
46+
47+
/// <summary>
48+
/// Gets the USWebCoatedSWOP profile.
49+
/// </summary>
50+
public static ColorProfile USWebCoatedSWOP
51+
=> Load("ImageMagick.Resources.ColorProfiles.CMYK", "USWebCoatedSWOP.icc");
52+
53+
private static ColorProfile Load(string resourcePath, string resourceName)
54+
{
55+
if (!_profiles.ContainsKey(resourceName))
56+
{
57+
lock (_syncRoot)
58+
{
59+
if (!_profiles.ContainsKey(resourceName))
60+
{
61+
using var stream = TypeHelper.GetManifestResourceStream(typeof(ColorProfile), resourcePath, resourceName);
62+
_profiles[resourceName] = new ColorProfile(stream);
63+
}
64+
}
65+
}
66+
67+
return _profiles[resourceName];
68+
}
69+
}

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheColorSpaceProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class TheColorSpaceProperty
1313
[Fact]
1414
public void ShouldReturnTheCorrectValue()
1515
{
16-
Assert.Equal(ColorSpace.sRGB, ColorProfile.AdobeRGB1998.ColorSpace);
17-
Assert.Equal(ColorSpace.sRGB, ColorProfile.AppleRGB.ColorSpace);
18-
Assert.Equal(ColorSpace.CMYK, ColorProfile.CoatedFOGRA39.ColorSpace);
19-
Assert.Equal(ColorSpace.sRGB, ColorProfile.ColorMatchRGB.ColorSpace);
20-
Assert.Equal(ColorSpace.sRGB, ColorProfile.SRGB.ColorSpace);
21-
Assert.Equal(ColorSpace.CMYK, ColorProfile.USWebCoatedSWOP.ColorSpace);
16+
Assert.Equal(ColorSpace.sRGB, ColorProfiles.AdobeRGB1998.ColorSpace);
17+
Assert.Equal(ColorSpace.sRGB, ColorProfiles.AppleRGB.ColorSpace);
18+
Assert.Equal(ColorSpace.CMYK, ColorProfiles.CoatedFOGRA39.ColorSpace);
19+
Assert.Equal(ColorSpace.sRGB, ColorProfiles.ColorMatchRGB.ColorSpace);
20+
Assert.Equal(ColorSpace.sRGB, ColorProfiles.SRGB.ColorSpace);
21+
Assert.Equal(ColorSpace.CMYK, ColorProfiles.USWebCoatedSWOP.ColorSpace);
2222
}
2323
}
2424
}

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheCopyrightProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class TheCopyrightProperty
1414
[Fact]
1515
public void ShouldReturnTheCorrectValue()
1616
{
17-
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfile.AdobeRGB1998.Copyright);
18-
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfile.AppleRGB.Copyright);
19-
Assert.Equal("Copyright 2007 Adobe Systems, Inc.", ColorProfile.CoatedFOGRA39.Copyright);
20-
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfile.ColorMatchRGB.Copyright);
21-
Assert.Equal("Copyright (c) 1998 Hewlett-Packard Company", ColorProfile.SRGB.Copyright);
22-
Assert.Equal("Copyright 2000 Adobe Systems, Inc.", ColorProfile.USWebCoatedSWOP.Copyright);
17+
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfiles.AdobeRGB1998.Copyright);
18+
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfiles.AppleRGB.Copyright);
19+
Assert.Equal("Copyright 2007 Adobe Systems, Inc.", ColorProfiles.CoatedFOGRA39.Copyright);
20+
Assert.Equal("Copyright 2000 Adobe Systems Incorporated", ColorProfiles.ColorMatchRGB.Copyright);
21+
Assert.Equal("Copyright (c) 1998 Hewlett-Packard Company", ColorProfiles.SRGB.Copyright);
22+
Assert.Equal("Copyright 2000 Adobe Systems, Inc.", ColorProfiles.USWebCoatedSWOP.Copyright);
2323
}
2424

2525
[Fact]

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheDescriptionProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class TheDescriptionProperty
1313
[Fact]
1414
public void ShouldReturnTheCorrectValue()
1515
{
16-
Assert.Equal("Adobe RGB (1998)", ColorProfile.AdobeRGB1998.Description);
17-
Assert.Equal("Apple RGB", ColorProfile.AppleRGB.Description);
18-
Assert.Equal("Coated FOGRA39 (ISO 12647-2:2004)", ColorProfile.CoatedFOGRA39.Description);
19-
Assert.Equal("ColorMatch RGB", ColorProfile.ColorMatchRGB.Description);
20-
Assert.Equal("sRGB IEC61966-2.1", ColorProfile.SRGB.Description);
21-
Assert.Equal("U.S. Web Coated (SWOP) v2", ColorProfile.USWebCoatedSWOP.Description);
16+
Assert.Equal("Adobe RGB (1998)", ColorProfiles.AdobeRGB1998.Description);
17+
Assert.Equal("Apple RGB", ColorProfiles.AppleRGB.Description);
18+
Assert.Equal("Coated FOGRA39 (ISO 12647-2:2004)", ColorProfiles.CoatedFOGRA39.Description);
19+
Assert.Equal("ColorMatch RGB", ColorProfiles.ColorMatchRGB.Description);
20+
Assert.Equal("sRGB IEC61966-2.1", ColorProfiles.SRGB.Description);
21+
Assert.Equal("U.S. Web Coated (SWOP) v2", ColorProfiles.USWebCoatedSWOP.Description);
2222
}
2323
}
2424
}

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheEmbeddedResources.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public class TheEmbeddedResources
1212
{
1313
public void ShouldHaveTheCorrectValue()
1414
{
15-
TestEmbeddedResource(ColorProfile.AdobeRGB1998);
16-
TestEmbeddedResource(ColorProfile.AppleRGB);
17-
TestEmbeddedResource(ColorProfile.CoatedFOGRA39);
18-
TestEmbeddedResource(ColorProfile.ColorMatchRGB);
19-
TestEmbeddedResource(ColorProfile.SRGB);
20-
TestEmbeddedResource(ColorProfile.USWebCoatedSWOP);
15+
TestEmbeddedResource(ColorProfiles.AdobeRGB1998);
16+
TestEmbeddedResource(ColorProfiles.AppleRGB);
17+
TestEmbeddedResource(ColorProfiles.CoatedFOGRA39);
18+
TestEmbeddedResource(ColorProfiles.ColorMatchRGB);
19+
TestEmbeddedResource(ColorProfiles.SRGB);
20+
TestEmbeddedResource(ColorProfiles.USWebCoatedSWOP);
2121
}
2222

2323
private static void TestEmbeddedResource(ColorProfile profile)

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheManufacturerProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class TheManufacturerProperty
1313
[Fact]
1414
public void ShouldReturnTheCorrectValue()
1515
{
16-
Assert.Null(ColorProfile.AdobeRGB1998.Manufacturer);
17-
Assert.Null(ColorProfile.AppleRGB.Manufacturer);
18-
Assert.Null(ColorProfile.CoatedFOGRA39.Manufacturer);
19-
Assert.Null(ColorProfile.ColorMatchRGB.Manufacturer);
20-
Assert.Equal("IEC http://www.iec.ch", ColorProfile.SRGB.Manufacturer);
21-
Assert.Null(ColorProfile.USWebCoatedSWOP.Manufacturer);
16+
Assert.Null(ColorProfiles.AdobeRGB1998.Manufacturer);
17+
Assert.Null(ColorProfiles.AppleRGB.Manufacturer);
18+
Assert.Null(ColorProfiles.CoatedFOGRA39.Manufacturer);
19+
Assert.Null(ColorProfiles.ColorMatchRGB.Manufacturer);
20+
Assert.Equal("IEC http://www.iec.ch", ColorProfiles.SRGB.Manufacturer);
21+
Assert.Null(ColorProfiles.USWebCoatedSWOP.Manufacturer);
2222
}
2323
}
2424
}

tests/Magick.NET.Core.Tests/Profiles/Color/ColorProfileTests/TheModelProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class TheModelProperty
1313
[Fact]
1414
public void ShouldReturnTheCorrectValue()
1515
{
16-
Assert.Null(ColorProfile.AdobeRGB1998.Model);
17-
Assert.Null(ColorProfile.AppleRGB.Model);
18-
Assert.Null(ColorProfile.CoatedFOGRA39.Model);
19-
Assert.Null(ColorProfile.ColorMatchRGB.Model);
20-
Assert.Equal("IEC 61966-2.1 Default RGB colour space - sRGB", ColorProfile.SRGB.Model);
21-
Assert.Null(ColorProfile.USWebCoatedSWOP.Model);
16+
Assert.Null(ColorProfiles.AdobeRGB1998.Model);
17+
Assert.Null(ColorProfiles.AppleRGB.Model);
18+
Assert.Null(ColorProfiles.CoatedFOGRA39.Model);
19+
Assert.Null(ColorProfiles.ColorMatchRGB.Model);
20+
Assert.Equal("IEC 61966-2.1 Default RGB colour space - sRGB", ColorProfiles.SRGB.Model);
21+
Assert.Null(ColorProfiles.USWebCoatedSWOP.Model);
2222
}
2323
}
2424
}

tests/Magick.NET.Tests/Coders/TheJpegCoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void ShouldDecodeCorrectly()
2828
public void ShouldReadImageProfile()
2929
{
3030
using var image = new MagickImage(Files.CMYKJPG);
31-
image.SetProfile(ColorProfile.USWebCoatedSWOP);
31+
image.SetProfile(ColorProfiles.USWebCoatedSWOP);
3232

3333
using var memoryStream = new MemoryStream();
3434
image.Write(memoryStream);

tests/Magick.NET.Tests/MagickImageTests/TheBlackPointCompensationProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ShouldBeDisabledByDefault()
1818
Assert.False(image.BlackPointCompensation);
1919
image.RenderingIntent = RenderingIntent.Relative;
2020

21-
image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.USWebCoatedSWOP);
21+
image.TransformColorSpace(ColorProfiles.SRGB, ColorProfiles.USWebCoatedSWOP);
2222
#if Q8 || Q16
2323
ColorAssert.Equal(new MagickColor("#da478d06323d"), image, 130, 100);
2424
#else
@@ -33,7 +33,7 @@ public void ShouldBeUsedInTheColorTransformation()
3333
image.RenderingIntent = RenderingIntent.Relative;
3434
image.BlackPointCompensation = true;
3535

36-
image.TransformColorSpace(ColorProfile.SRGB, ColorProfile.USWebCoatedSWOP);
36+
image.TransformColorSpace(ColorProfiles.SRGB, ColorProfiles.USWebCoatedSWOP);
3737
#if Q8 || Q16
3838
ColorAssert.Equal(new MagickColor("#cd0a844e3209"), image, 130, 100);
3939
#else

0 commit comments

Comments
 (0)