Browse Source

Use Target Type new only when apparent

pull/2958/head
Stefan Nikolei 8 months ago
parent
commit
18b8b662e9
  1. 3
      .editorconfig
  2. 4
      src/ImageSharp/Advanced/ParallelExecutionSettings.cs
  3. 4
      src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
  4. 2
      src/ImageSharp/Color/Color.WernerPalette.cs
  5. 6
      src/ImageSharp/Color/Color.cs
  6. 8
      src/ImageSharp/ColorProfiles/CieLab.cs
  7. 10
      src/ImageSharp/ColorProfiles/CieLch.cs
  8. 8
      src/ImageSharp/ColorProfiles/CieLchuv.cs
  9. 4
      src/ImageSharp/ColorProfiles/CieLuv.cs
  10. 8
      src/ImageSharp/ColorProfiles/CieXyy.cs
  11. 8
      src/ImageSharp/ColorProfiles/CieXyz.cs
  12. 6
      src/ImageSharp/ColorProfiles/Cmyk.cs
  13. 2
      src/ImageSharp/ColorProfiles/ColorProfileConverter.cs
  14. 16
      src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs
  15. 8
      src/ImageSharp/ColorProfiles/Hsl.cs
  16. 10
      src/ImageSharp/ColorProfiles/Hsv.cs
  17. 8
      src/ImageSharp/ColorProfiles/HunterLab.cs
  18. 6
      src/ImageSharp/ColorProfiles/Icc/Calculators/ColorTrcCalculator.cs
  19. 2
      src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs
  20. 2
      src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs
  21. 10
      src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs
  22. 4
      src/ImageSharp/ColorProfiles/Icc/Calculators/LutEntryCalculator.cs
  23. 2
      src/ImageSharp/ColorProfiles/Icc/Calculators/MatrixCalculator.cs
  24. 2
      src/ImageSharp/ColorProfiles/Icc/CompactSrgbV4Profile.cs
  25. 4
      src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs
  26. 12
      src/ImageSharp/ColorProfiles/KnownChromaticAdaptationMatrices.cs
  27. 38
      src/ImageSharp/ColorProfiles/KnownRgbWorkingSpaces.cs
  28. 18
      src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs
  29. 4
      src/ImageSharp/ColorProfiles/Lms.cs
  30. 6
      src/ImageSharp/ColorProfiles/Rgb.cs
  31. 6
      src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs
  32. 2
      src/ImageSharp/ColorProfiles/Y.cs
  33. 6
      src/ImageSharp/ColorProfiles/YCbCr.cs
  34. 6
      src/ImageSharp/ColorProfiles/YccK.cs
  35. 2
      src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs
  36. 2
      src/ImageSharp/Common/Helpers/Numerics.cs
  37. 2
      src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs
  38. 2
      src/ImageSharp/Common/Helpers/SimdUtils.cs
  39. 2
      src/ImageSharp/Common/Helpers/TolerantMath.cs
  40. 4
      src/ImageSharp/Common/Helpers/UnitConverter.cs
  41. 2
      src/ImageSharp/Compression/Zlib/Deflater.cs
  42. 2
      src/ImageSharp/Compression/Zlib/DeflaterEngine.cs
  43. 8
      src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
  44. 2
      src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs
  45. 2
      src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs
  46. 2
      src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs
  47. 2
      src/ImageSharp/Configuration.cs
  48. 2
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  49. 16
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  50. 6
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  51. 2
      src/ImageSharp/Formats/Bmp/BmpFormat.cs
  52. 16
      src/ImageSharp/Formats/Bmp/BmpMetadata.cs
  53. 8
      src/ImageSharp/Formats/Cur/CurFrameMetadata.cs
  54. 4
      src/ImageSharp/Formats/Cur/CurMetadata.cs
  55. 2
      src/ImageSharp/Formats/DecoderOptions.cs
  56. 12
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  57. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  58. 2
      src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
  59. 2
      src/ImageSharp/Formats/Gif/GifMetadata.cs
  60. 2
      src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs
  61. 2
      src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs
  62. 8
      src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs
  63. 4
      src/ImageSharp/Formats/Ico/IcoMetadata.cs
  64. 12
      src/ImageSharp/Formats/Icon/IconDecoderCore.cs
  65. 6
      src/ImageSharp/Formats/Icon/IconEncoderCore.cs
  66. 2
      src/ImageSharp/Formats/ImageFormatManager.cs
  67. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
  68. 8
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs
  69. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.TiffYccKScalar.cs
  70. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrScalar.cs
  71. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKScalar.cs
  72. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
  73. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs
  74. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
  75. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  76. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs
  77. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
  78. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs
  79. 4
      src/ImageSharp/Formats/Jpeg/Components/Encoder/Component.cs
  80. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
  81. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
  82. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs
  83. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs
  84. 2
      src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs
  85. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  86. 34
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  87. 84
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs
  88. 2
      src/ImageSharp/Formats/Jpeg/JpegFormat.cs
  89. 4
      src/ImageSharp/Formats/Jpeg/JpegMetadata.cs
  90. 8
      src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
  91. 4
      src/ImageSharp/Formats/Pbm/PbmMetadata.cs
  92. 8
      src/ImageSharp/Formats/Pbm/PlainDecoder.cs
  93. 4
      src/ImageSharp/Formats/Png/Chunks/PngPhysical.cs
  94. 2
      src/ImageSharp/Formats/Png/PngDecoder.cs
  95. 34
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  96. 2
      src/ImageSharp/Formats/Png/PngDecoderOptions.cs
  97. 2
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  98. 2
      src/ImageSharp/Formats/Png/PngFormat.cs
  99. 6
      src/ImageSharp/Formats/Png/PngFrameMetadata.cs
  100. 4
      src/ImageSharp/Formats/Png/PngMetadata.cs

3
.editorconfig

@ -161,6 +161,9 @@ csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
# ReSharper inspection severities
resharper_arrange_object_creation_when_type_evident_highlighting = error
resharper_arrange_object_creation_when_type_not_evident_highlighting = error
# "Null" checking preferences
csharp_style_throw_expression = true:warning
csharp_style_conditional_delegate_call = true:warning

4
src/ImageSharp/Advanced/ParallelExecutionSettings.cs

@ -79,7 +79,7 @@ public readonly struct ParallelExecutionSettings
{
Guard.MustBeGreaterThan(multiplier, 0, nameof(multiplier));
return new(
return new ParallelExecutionSettings(
this.MaxDegreeOfParallelism,
this.MinimumPixelsProcessedPerTask * multiplier,
this.MemoryAllocator);
@ -92,6 +92,6 @@ public readonly struct ParallelExecutionSettings
/// <returns>The <see cref="ParallelExecutionSettings"/>.</returns>
public static ParallelExecutionSettings FromConfiguration(Configuration configuration)
{
return new(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
return new ParallelExecutionSettings(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
}
}

4
src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs

@ -139,7 +139,7 @@ public static partial class ParallelRowIterator
}
int yMax = Math.Min(yMin + this.stepY, this.maxY);
RowInterval rows = new RowInterval(yMin, yMax);
RowInterval rows = new(yMin, yMax);
// Skip the safety copy when invoking a potentially impure method on a readonly field
Unsafe.AsRef(in this.operation).Invoke(in rows);
@ -185,7 +185,7 @@ public static partial class ParallelRowIterator
}
int yMax = Math.Min(yMin + this.stepY, this.maxY);
RowInterval rows = new RowInterval(yMin, yMax);
RowInterval rows = new(yMin, yMax);
using IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.bufferLength);

2
src/ImageSharp/Color/Color.WernerPalette.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp;
/// </content>
public partial struct Color
{
private static readonly Lazy<Color[]> WernerPaletteLazy = new Lazy<Color[]>(CreateWernerPalette, true);
private static readonly Lazy<Color[]> WernerPaletteLazy = new(CreateWernerPalette, true);
/// <summary>
/// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.

6
src/ImageSharp/Color/Color.cs

@ -81,10 +81,10 @@ public readonly partial struct Color : IEquatable<Color>
PixelTypeInfo info = TPixel.GetPixelTypeInfo();
if (info.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentBitDepth.Bit32)
{
return new(source.ToScaledVector4());
return new Color(source.ToScaledVector4());
}
return new(source);
return new Color(source);
}
/// <summary>
@ -120,7 +120,7 @@ public readonly partial struct Color : IEquatable<Color>
{
for (int i = 0; i < destination.Length; i++)
{
destination[i] = new(source[i]);
destination[i] = new Color(source[i]);
}
}
}

8
src/ImageSharp/ColorProfiles/CieLab.cs

@ -88,7 +88,7 @@ public readonly struct CieLab : IProfileConnectingSpace<CieLab, CieXyz>
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 128F, 128F);
v3 /= new Vector3(100F, 255F, 255F);
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -97,7 +97,7 @@ public readonly struct CieLab : IProfileConnectingSpace<CieLab, CieXyz>
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100F, 255, 255);
v3 -= new Vector3(0, 128F, 128F);
return new(v3);
return new CieLab(v3);
}
/// <inheritdoc/>
@ -145,7 +145,7 @@ public readonly struct CieLab : IProfileConnectingSpace<CieLab, CieXyz>
float a = 500F * (fx - fy);
float b = 200F * (fy - fz);
return new(l, a, b);
return new CieLab(l, a, b);
}
/// <inheritdoc/>
@ -182,7 +182,7 @@ public readonly struct CieLab : IProfileConnectingSpace<CieLab, CieXyz>
Vector3 wxyz = new(whitePoint.X, whitePoint.Y, whitePoint.Z);
Vector3 xyzr = new(xr, yr, zr);
return new(xyzr * wxyz);
return new CieXyz(xyzr * wxyz);
}
/// <inheritdoc/>

10
src/ImageSharp/ColorProfiles/CieLch.cs

@ -25,7 +25,7 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLch(float l, float c, float h)
: this(new(l, c, h))
: this(new Vector3(l, c, h))
{
}
@ -100,7 +100,7 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 200, 0);
v3 /= new Vector3(100, 400, 360);
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -109,7 +109,7 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100, 400, 360);
v3 -= new Vector3(0, 200, 0);
return new(v3, true);
return new CieLch(v3, true);
}
/// <inheritdoc/>
@ -155,7 +155,7 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
hDegrees += 360;
}
return new(l, c, hDegrees);
return new CieLch(l, c, hDegrees);
}
/// <inheritdoc/>
@ -181,7 +181,7 @@ public readonly struct CieLch : IColorProfile<CieLch, CieLab>
float a = c * MathF.Cos(hRadians);
float b = c * MathF.Sin(hRadians);
return new(l, a, b);
return new CieLab(l, a, b);
}
/// <inheritdoc/>

8
src/ImageSharp/ColorProfiles/CieLchuv.cs

@ -25,7 +25,7 @@ public readonly struct CieLchuv : IColorProfile<CieLchuv, CieXyz>
/// <param name="h">The hue in degrees.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CieLchuv(float l, float c, float h)
: this(new(l, c, h))
: this(new Vector3(l, c, h))
{
}
@ -97,7 +97,7 @@ public readonly struct CieLchuv : IColorProfile<CieLchuv, CieXyz>
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 200, 0);
v3 /= new Vector3(100, 400, 360);
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -106,7 +106,7 @@ public readonly struct CieLchuv : IColorProfile<CieLchuv, CieXyz>
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100, 400, 360);
v3 -= new Vector3(0, 200, 0);
return new(v3, true);
return new CieLchuv(v3, true);
}
/// <inheritdoc/>
@ -154,7 +154,7 @@ public readonly struct CieLchuv : IColorProfile<CieLchuv, CieXyz>
hDegrees += 360;
}
return new(l, c, hDegrees);
return new CieLchuv(l, c, hDegrees);
}
/// <inheritdoc/>

4
src/ImageSharp/ColorProfiles/CieLuv.cs

@ -134,7 +134,7 @@ public readonly struct CieLuv : IColorProfile<CieLuv, CieXyz>
v = 0;
}
return new((float)l, (float)u, (float)v);
return new CieLuv((float)l, (float)u, (float)v);
}
/// <inheritdoc/>
@ -188,7 +188,7 @@ public readonly struct CieLuv : IColorProfile<CieLuv, CieXyz>
z = 0;
}
return new((float)x, (float)y, (float)z);
return new CieXyz((float)x, (float)y, (float)z);
}
/// <inheritdoc/>

8
src/ImageSharp/ColorProfiles/CieXyy.cs

@ -122,10 +122,10 @@ public readonly struct CieXyy : IColorProfile<CieXyy, CieXyz>
if (float.IsNaN(x) || float.IsNaN(y))
{
return new(0, 0, source.Y);
return new CieXyy(0, 0, source.Y);
}
return new(x, y, source.Y);
return new CieXyy(x, y, source.Y);
}
/// <inheritdoc/>
@ -144,14 +144,14 @@ public readonly struct CieXyy : IColorProfile<CieXyy, CieXyz>
{
if (MathF.Abs(this.Y) < Constants.Epsilon)
{
return new(0, 0, this.Yl);
return new CieXyz(0, 0, this.Yl);
}
float x = (this.X * this.Yl) / this.Y;
float y = this.Yl;
float z = ((1 - this.X - this.Y) * y) / this.Y;
return new(x, y, z);
return new CieXyz(x, y, z);
}
/// <inheritdoc/>

8
src/ImageSharp/ColorProfiles/CieXyz.cs

@ -88,7 +88,7 @@ public readonly struct CieXyz : IProfileConnectingSpace<CieXyz, CieXyz>
{
Vector3 v3 = default;
v3 += this.AsVector3Unsafe();
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -97,13 +97,13 @@ public readonly struct CieXyz : IProfileConnectingSpace<CieXyz, CieXyz>
Vector3 v3 = default;
v3 += this.AsVector3Unsafe();
v3 *= 32768F / 65535;
return new(v3, 1F);
return new Vector4(v3, 1F);
}
internal static CieXyz FromVector4(Vector4 source)
{
Vector3 v3 = source.AsVector3();
return new(v3);
return new CieXyz(v3);
}
/// <inheritdoc/>
@ -111,7 +111,7 @@ public readonly struct CieXyz : IProfileConnectingSpace<CieXyz, CieXyz>
{
Vector3 v3 = source.AsVector3();
v3 *= 65535 / 32768F;
return new(v3);
return new CieXyz(v3);
}
/// <inheritdoc/>

6
src/ImageSharp/ColorProfiles/Cmyk.cs

@ -26,7 +26,7 @@ public readonly struct Cmyk : IColorProfile<Cmyk, Rgb>
/// <param name="k">The keyline black component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Cmyk(float c, float m, float y, float k)
: this(new(c, m, y, k))
: this(new Vector4(c, m, y, k))
{
}
@ -138,12 +138,12 @@ public readonly struct Cmyk : IColorProfile<Cmyk, Rgb>
if (k.X >= 1F - Constants.Epsilon)
{
return new(0, 0, 0, 1F);
return new Cmyk(0, 0, 0, 1F);
}
cmy = (cmy - k) / (Vector3.One - k);
return new(cmy.X, cmy.Y, cmy.Z, k.X);
return new Cmyk(cmy.X, cmy.Y, cmy.Z, k.X);
}
/// <inheritdoc/>

2
src/ImageSharp/ColorProfiles/ColorProfileConverter.cs

@ -12,7 +12,7 @@ public class ColorProfileConverter
/// Initializes a new instance of the <see cref="ColorProfileConverter"/> class.
/// </summary>
public ColorProfileConverter()
: this(new())
: this(new ColorConversionOptions())
{
}

16
src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs

@ -57,11 +57,11 @@ internal static class ColorProfileConverterExtensionsIcc
ConversionParams sourceParams = new(converter.Options.SourceIccProfile, toPcs: true);
ConversionParams targetParams = new(converter.Options.TargetIccProfile, toPcs: false);
ColorProfileConverter pcsConverter = new(new()
ColorProfileConverter pcsConverter = new(new ColorConversionOptions
{
MemoryAllocator = converter.Options.MemoryAllocator,
SourceWhitePoint = new(converter.Options.SourceIccProfile.Header.PcsIlluminant),
TargetWhitePoint = new(converter.Options.TargetIccProfile.Header.PcsIlluminant),
SourceWhitePoint = new CieXyz(converter.Options.SourceIccProfile.Header.PcsIlluminant),
TargetWhitePoint = new CieXyz(converter.Options.TargetIccProfile.Header.PcsIlluminant),
});
// Normalize the source, then convert to the PCS space.
@ -101,11 +101,11 @@ internal static class ColorProfileConverterExtensionsIcc
ConversionParams sourceParams = new(converter.Options.SourceIccProfile, toPcs: true);
ConversionParams targetParams = new(converter.Options.TargetIccProfile, toPcs: false);
ColorProfileConverter pcsConverter = new(new()
ColorProfileConverter pcsConverter = new(new ColorConversionOptions
{
MemoryAllocator = converter.Options.MemoryAllocator,
SourceWhitePoint = new(converter.Options.SourceIccProfile.Header.PcsIlluminant),
TargetWhitePoint = new(converter.Options.TargetIccProfile.Header.PcsIlluminant),
SourceWhitePoint = new CieXyz(converter.Options.SourceIccProfile.Header.PcsIlluminant),
TargetWhitePoint = new CieXyz(converter.Options.TargetIccProfile.Header.PcsIlluminant),
});
using IMemoryOwner<Vector4> pcsBuffer = converter.Options.MemoryAllocator.Allocate<Vector4>(source.Length);
@ -355,7 +355,7 @@ internal static class ColorProfileConverterExtensionsIcc
vector = Vector3.Max(vector, Vector3.Zero);
}
xyz = new(AdjustPcsFromV2BlackPoint(vector));
xyz = new CieXyz(AdjustPcsFromV2BlackPoint(vector));
}
// when converting from PCS to device with v2 perceptual intent
@ -371,7 +371,7 @@ internal static class ColorProfileConverterExtensionsIcc
vector = Vector3.Max(vector, Vector3.Zero);
}
xyz = new(vector);
xyz = new CieXyz(vector);
}
switch (targetParams.PcsType)

8
src/ImageSharp/ColorProfiles/Hsl.cs

@ -24,7 +24,7 @@ public readonly struct Hsl : IColorProfile<Hsl, Rgb>
/// <param name="l">The l value (lightness) component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Hsl(float h, float s, float l)
: this(new(h, s, l))
: this(new Vector3(h, s, l))
{
}
@ -141,7 +141,7 @@ public readonly struct Hsl : IColorProfile<Hsl, Rgb>
if (MathF.Abs(chroma) < Constants.Epsilon)
{
return new(0F, s, l);
return new Hsl(0F, s, l);
}
if (MathF.Abs(r - max) < Constants.Epsilon)
@ -172,7 +172,7 @@ public readonly struct Hsl : IColorProfile<Hsl, Rgb>
s = chroma / (2F - max - min);
}
return new(h, s, l);
return new Hsl(h, s, l);
}
/// <inheritdoc/>
@ -213,7 +213,7 @@ public readonly struct Hsl : IColorProfile<Hsl, Rgb>
}
}
return new(r, g, b);
return new Rgb(r, g, b);
}
/// <inheritdoc/>

10
src/ImageSharp/ColorProfiles/Hsv.cs

@ -24,7 +24,7 @@ public readonly struct Hsv : IColorProfile<Hsv, Rgb>
/// <param name="v">The v value (brightness) component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Hsv(float h, float s, float v)
: this(new(h, s, v))
: this(new Vector3(h, s, v))
{
}
@ -139,7 +139,7 @@ public readonly struct Hsv : IColorProfile<Hsv, Rgb>
if (MathF.Abs(chroma) < Constants.Epsilon)
{
return new(0, s, v);
return new Hsv(0, s, v);
}
if (MathF.Abs(r - max) < Constants.Epsilon)
@ -163,7 +163,7 @@ public readonly struct Hsv : IColorProfile<Hsv, Rgb>
s = chroma / v;
return new(h, s, v);
return new Hsv(h, s, v);
}
/// <inheritdoc/>
@ -185,7 +185,7 @@ public readonly struct Hsv : IColorProfile<Hsv, Rgb>
if (MathF.Abs(s) < Constants.Epsilon)
{
return new(v, v, v);
return new Rgb(v, v, v);
}
float h = (MathF.Abs(this.H - 360) < Constants.Epsilon) ? 0 : this.H / 60;
@ -236,7 +236,7 @@ public readonly struct Hsv : IColorProfile<Hsv, Rgb>
break;
}
return new(r, g, b);
return new Rgb(r, g, b);
}
/// <inheritdoc/>

8
src/ImageSharp/ColorProfiles/HunterLab.cs

@ -87,7 +87,7 @@ public readonly struct HunterLab : IColorProfile<HunterLab, CieXyz>
v3 += this.AsVector3Unsafe();
v3 += new Vector3(0, 128F, 128F);
v3 /= new Vector3(100F, 255F, 255F);
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -96,7 +96,7 @@ public readonly struct HunterLab : IColorProfile<HunterLab, CieXyz>
Vector3 v3 = source.AsVector3();
v3 *= new Vector3(100F, 255, 255);
v3 -= new Vector3(0, 128F, 128F);
return new(v3);
return new HunterLab(v3);
}
/// <inheritdoc/>
@ -151,7 +151,7 @@ public readonly struct HunterLab : IColorProfile<HunterLab, CieXyz>
b = 0;
}
return new(l, a, b);
return new HunterLab(l, a, b);
}
/// <inheritdoc/>
@ -184,7 +184,7 @@ public readonly struct HunterLab : IColorProfile<HunterLab, CieXyz>
float x = (((a / ka) * sqrtPow) + pow) * xn;
float z = (((b / kb) * sqrtPow) - pow) * (-zn);
return new(x, y, z);
return new CieXyz(x, y, z);
}
/// <inheritdoc/>

6
src/ImageSharp/ColorProfiles/Icc/Calculators/ColorTrcCalculator.cs

@ -23,12 +23,12 @@ internal class ColorTrcCalculator : IVector4Calculator
bool toPcs)
{
this.toPcs = toPcs;
this.curveCalculator = new([redTrc, greenTrc, blueTrc], !toPcs);
this.curveCalculator = new TrcCalculator([redTrc, greenTrc, blueTrc], !toPcs);
Vector3 mr = redMatrixColumn.Data[0];
Vector3 mg = greenMatrixColumn.Data[0];
Vector3 mb = blueMatrixColumn.Data[0];
this.matrix = new(mr.X, mr.Y, mr.Z, 0, mg.X, mg.Y, mg.Z, 0, mb.X, mb.Y, mb.Z, 0, 0, 0, 0, 1);
this.matrix = new Matrix4x4(mr.X, mr.Y, mr.Z, 0, mg.X, mg.Y, mg.Z, 0, mb.X, mb.Y, mb.Z, 0, 0, 0, 0, 1);
if (!toPcs)
{
@ -58,7 +58,7 @@ internal class ColorTrcCalculator : IVector4Calculator
// when data to PCS, upstream process provides scaled XYZ
// but input to calculator is descaled XYZ
// (see DemoMaxICC IccCmm.cpp : CIccXformMatrixTRC::Apply)
xyz = new(CieXyz.FromScaledVector4(xyz).AsVector3Unsafe(), 1);
xyz = new Vector4(CieXyz.FromScaledVector4(xyz).AsVector3Unsafe(), 1);
return this.curveCalculator.Calculate(xyz);
}
}

2
src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs

@ -31,7 +31,7 @@ internal partial class CurveCalculator : ISingleCalculator
}
else
{
this.lutCalculator = new(entry.CurveData, inverted);
this.lutCalculator = new LutCalculator(entry.CurveData, inverted);
this.type = CalculationType.Lut;
}
}

2
src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs

@ -12,7 +12,7 @@ internal class GrayTrcCalculator : IVector4Calculator
private readonly TrcCalculator calculator;
public GrayTrcCalculator(IccTagDataEntry grayTrc, bool toPcs)
=> this.calculator = new(new IccTagDataEntry[] { grayTrc }, !toPcs);
=> this.calculator = new TrcCalculator(new IccTagDataEntry[] { grayTrc }, !toPcs);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4 Calculate(Vector4 value) => this.calculator.Calculate(value);

10
src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs

@ -109,27 +109,27 @@ internal partial class LutABCalculator : IVector4Calculator
if (hasACurve)
{
this.curveACalculator = new(curveA, false);
this.curveACalculator = new TrcCalculator(curveA, false);
}
if (hasBCurve)
{
this.curveBCalculator = new(curveB, false);
this.curveBCalculator = new TrcCalculator(curveB, false);
}
if (hasMCurve)
{
this.curveMCalculator = new(curveM, false);
this.curveMCalculator = new TrcCalculator(curveM, false);
}
if (hasMatrix)
{
this.matrixCalculator = new(matrix3x3.Value, matrix3x1.Value);
this.matrixCalculator = new MatrixCalculator(matrix3x3.Value, matrix3x1.Value);
}
if (hasClut)
{
this.clutCalculator = new(clut);
this.clutCalculator = new ClutCalculator(clut);
}
}
}

4
src/ImageSharp/ColorProfiles/Icc/Calculators/LutEntryCalculator.cs

@ -61,7 +61,7 @@ internal class LutEntryCalculator : IVector4Calculator
{
this.inputCurve = InitLut(inputCurve);
this.outputCurve = InitLut(outputCurve);
this.clutCalculator = new(clut);
this.clutCalculator = new ClutCalculator(clut);
this.matrix = matrix;
this.doTransform = !matrix.IsIdentity && inputCurve.Length == 3;
@ -72,7 +72,7 @@ internal class LutEntryCalculator : IVector4Calculator
LutCalculator[] calculators = new LutCalculator[curves.Length];
for (int i = 0; i < curves.Length; i++)
{
calculators[i] = new(curves[i].Values, false);
calculators[i] = new LutCalculator(curves[i].Values, false);
}
return calculators;

2
src/ImageSharp/ColorProfiles/Icc/Calculators/MatrixCalculator.cs

@ -14,7 +14,7 @@ internal class MatrixCalculator : IVector4Calculator
public MatrixCalculator(Matrix4x4 matrix3x3, Vector3 matrix3x1)
{
this.matrix2D = matrix3x3;
this.matrix1D = new(matrix3x1, 0);
this.matrix1D = new Vector4(matrix3x1, 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

2
src/ImageSharp/ColorProfiles/Icc/CompactSrgbV4Profile.cs

@ -37,6 +37,6 @@ internal static class CompactSrgbV4Profile
{
byte[] buffer = new byte[Data.Length];
Data.CopyTo(buffer);
return new(buffer);
return new IccProfile(buffer);
}
}

4
src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs

@ -91,7 +91,7 @@ internal abstract partial class IccConverterBase
throw new InvalidIccProfileException("Missing matrix column or channel.");
}
return new(
return new ColorTrcCalculator(
redMatrixColumn,
greenMatrixColumn,
blueMatrixColumn,
@ -104,6 +104,6 @@ internal abstract partial class IccConverterBase
private static GrayTrcCalculator InitGrayTrc(IccProfile profile, bool toPcs)
{
IccTagDataEntry entry = GetTag(profile, IccProfileTag.GrayTrc);
return new(entry, toPcs);
return new GrayTrcCalculator(entry, toPcs);
}
}

12
src/ImageSharp/ColorProfiles/KnownChromaticAdaptationMatrices.cs

@ -24,7 +24,7 @@ public static class KnownChromaticAdaptationMatrices
/// von Kries chromatic adaptation transform matrix (Hunt-Pointer-Estevez adjusted for D65)
/// </summary>
public static readonly Matrix4x4 VonKriesHPEAdjusted
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 0.40024F,
M12 = 0.7076F,
@ -42,7 +42,7 @@ public static class KnownChromaticAdaptationMatrices
/// von Kries chromatic adaptation transform matrix (Hunt-Pointer-Estevez for equal energy)
/// </summary>
public static readonly Matrix4x4 VonKriesHPE
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 0.3897F,
M12 = 0.6890F,
@ -65,7 +65,7 @@ public static class KnownChromaticAdaptationMatrices
/// Bradford chromatic adaptation transform matrix (used in CMCCAT97)
/// </summary>
public static readonly Matrix4x4 Bradford
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 0.8951F,
M12 = 0.2664F,
@ -83,7 +83,7 @@ public static class KnownChromaticAdaptationMatrices
/// Spectral sharpening and the Bradford transform
/// </summary>
public static readonly Matrix4x4 BradfordSharp
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 1.2694F,
M12 = -0.0988F,
@ -101,7 +101,7 @@ public static class KnownChromaticAdaptationMatrices
/// CMCCAT2000 (fitted from all available color data sets)
/// </summary>
public static readonly Matrix4x4 CMCCAT2000
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 0.7982F,
M12 = 0.3389F,
@ -119,7 +119,7 @@ public static class KnownChromaticAdaptationMatrices
/// CAT02 (optimized for minimizing CIELAB differences)
/// </summary>
public static readonly Matrix4x4 CAT02
= Matrix4x4.Transpose(new()
= Matrix4x4.Transpose(new Matrix4x4
{
M11 = 0.7328F,
M12 = 0.4296F,

38
src/ImageSharp/ColorProfiles/KnownRgbWorkingSpaces.cs

@ -18,96 +18,96 @@ public static class KnownRgbWorkingSpaces
/// Uses proper companding function, according to:
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_Rgb_to_XYZ.html"/>
/// </remarks>
public static readonly RgbWorkingSpace SRgb = new SRgbWorkingSpace(KnownIlluminants.D65, new(new(0.6400F, 0.3300F), new(0.3000F, 0.6000F), new(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace SRgb = new SRgbWorkingSpace(KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Simplified sRgb working space (uses <see cref="GammaCompanding">gamma companding</see> instead of <see cref="SRgbCompanding"/>).
/// See also <see cref="SRgb"/>.
/// </summary>
public static readonly RgbWorkingSpace SRgbSimplified = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new(new(0.6400F, 0.3300F), new(0.3000F, 0.6000F), new(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace SRgbSimplified = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Rec. 709 (ITU-R Recommendation BT.709) working space.
/// </summary>
public static readonly RgbWorkingSpace Rec709 = new Rec709WorkingSpace(KnownIlluminants.D65, new(new(0.64F, 0.33F), new(0.30F, 0.60F), new(0.15F, 0.06F)));
public static readonly RgbWorkingSpace Rec709 = new Rec709WorkingSpace(KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F)));
/// <summary>
/// Rec. 2020 (ITU-R Recommendation BT.2020F) working space.
/// </summary>
public static readonly RgbWorkingSpace Rec2020 = new Rec2020WorkingSpace(KnownIlluminants.D65, new(new(0.708F, 0.292F), new(0.170F, 0.797F), new(0.131F, 0.046F)));
public static readonly RgbWorkingSpace Rec2020 = new Rec2020WorkingSpace(KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F)));
/// <summary>
/// ECI Rgb v2 working space.
/// </summary>
public static readonly RgbWorkingSpace ECIRgbv2 = new LWorkingSpace(KnownIlluminants.D50, new(new(0.6700F, 0.3300F), new(0.2100F, 0.7100F), new(0.1400F, 0.0800F)));
public static readonly RgbWorkingSpace ECIRgbv2 = new LWorkingSpace(KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
/// <summary>
/// Adobe Rgb (1998) working space.
/// </summary>
public static readonly RgbWorkingSpace AdobeRgb1998 = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new(new(0.6400F, 0.3300F), new(0.2100F, 0.7100F), new(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace AdobeRgb1998 = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Apple sRgb working space.
/// </summary>
public static readonly RgbWorkingSpace ApplesRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D65, new(new(0.6250F, 0.3400F), new(0.2800F, 0.5950F), new(0.1550F, 0.0700F)));
public static readonly RgbWorkingSpace ApplesRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
/// <summary>
/// Best Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace BestRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new(new(0.7347F, 0.2653F), new(0.2150F, 0.7750F), new(0.1300F, 0.0350F)));
public static readonly RgbWorkingSpace BestRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
/// <summary>
/// Beta Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace BetaRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new(new(0.6888F, 0.3112F), new(0.1986F, 0.7551F), new(0.1265F, 0.0352F)));
public static readonly RgbWorkingSpace BetaRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F)));
/// <summary>
/// Bruce Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace BruceRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new(new(0.6400F, 0.3300F), new(0.2800F, 0.6500F), new(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace BruceRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// CIE Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace CIERgb = new GammaWorkingSpace(2.2F, KnownIlluminants.E, new(new(0.7350F, 0.2650F), new(0.2740F, 0.7170F), new(0.1670F, 0.0090F)));
public static readonly RgbWorkingSpace CIERgb = new GammaWorkingSpace(2.2F, KnownIlluminants.E, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F)));
/// <summary>
/// ColorMatch Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace ColorMatchRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D50, new(new(0.6300F, 0.3400F), new(0.2950F, 0.6050F), new(0.1500F, 0.0750F)));
public static readonly RgbWorkingSpace ColorMatchRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F)));
/// <summary>
/// Don Rgb 4 working space.
/// </summary>
public static readonly RgbWorkingSpace DonRgb4 = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new(new(0.6960F, 0.3000F), new(0.2150F, 0.7650F), new(0.1300F, 0.0350F)));
public static readonly RgbWorkingSpace DonRgb4 = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
/// <summary>
/// Ekta Space PS5 working space.
/// </summary>
public static readonly RgbWorkingSpace EktaSpacePS5 = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new(new(0.6950F, 0.3050F), new(0.2600F, 0.7000F), new(0.1100F, 0.0050F)));
public static readonly RgbWorkingSpace EktaSpacePS5 = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F)));
/// <summary>
/// NTSC Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace NTSCRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.C, new(new(0.6700F, 0.3300F), new(0.2100F, 0.7100F), new(0.1400F, 0.0800F)));
public static readonly RgbWorkingSpace NTSCRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.C, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
/// <summary>
/// PAL/SECAM Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace PALSECAMRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new(new(0.6400F, 0.3300F), new(0.2900F, 0.6000F), new(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace PALSECAMRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// ProPhoto Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace ProPhotoRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D50, new(new(0.7347F, 0.2653F), new(0.1596F, 0.8404F), new(0.0366F, 0.0001F)));
public static readonly RgbWorkingSpace ProPhotoRgb = new GammaWorkingSpace(1.8F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F)));
/// <summary>
/// SMPTE-C Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace SMPTECRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new(new(0.6300F, 0.3400F), new(0.3100F, 0.5950F), new(0.1550F, 0.0700F)));
public static readonly RgbWorkingSpace SMPTECRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
/// <summary>
/// Wide Gamut Rgb working space.
/// </summary>
public static readonly RgbWorkingSpace WideGamutRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new(new(0.7350F, 0.2650F), new(0.1150F, 0.8260F), new(0.1570F, 0.0180F)));
public static readonly RgbWorkingSpace WideGamutRgb = new GammaWorkingSpace(2.2F, KnownIlluminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F)));
}

18
src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs

@ -16,47 +16,47 @@ public static class KnownYCbCrMatrices
/// ITU-R BT.601 (SD video standard).
/// </summary>
public static readonly YCbCrTransform BT601 = new(
new(
new Matrix4x4(
0.299000F, 0.587000F, 0.114000F, 0F,
-0.168736F, -0.331264F, 0.500000F, 0F,
0.500000F, -0.418688F, -0.081312F, 0F,
0F, 0F, 0F, 1F),
new(
new Matrix4x4(
1.000000F, 0.000000F, 1.402000F, 0F,
1.000000F, -0.344136F, -0.714136F, 0F,
1.000000F, 1.772000F, 0.000000F, 0F,
0F, 0F, 0F, 1F),
new(0F, 0.5F, 0.5F));
new Vector3(0F, 0.5F, 0.5F));
/// <summary>
/// ITU-R BT.709 (HD video, sRGB standard).
/// </summary>
public static readonly YCbCrTransform BT709 = new(
new(
new Matrix4x4(
0.212600F, 0.715200F, 0.072200F, 0F,
-0.114572F, -0.385428F, 0.500000F, 0F,
0.500000F, -0.454153F, -0.045847F, 0F,
0F, 0F, 0F, 1F),
new(
new Matrix4x4(
1.000000F, 0.000000F, 1.574800F, 0F,
1.000000F, -0.187324F, -0.468124F, 0F,
1.000000F, 1.855600F, 0.000000F, 0F,
0F, 0F, 0F, 1F),
new(0F, 0.5F, 0.5F));
new Vector3(0F, 0.5F, 0.5F));
/// <summary>
/// ITU-R BT.2020 (UHD/4K video standard).
/// </summary>
public static readonly YCbCrTransform BT2020 = new(
new(
new Matrix4x4(
0.262700F, 0.678000F, 0.059300F, 0F,
-0.139630F, -0.360370F, 0.500000F, 0F,
0.500000F, -0.459786F, -0.040214F, 0F,
0F, 0F, 0F, 1F),
new(
new Matrix4x4(
1.000000F, 0.000000F, 1.474600F, 0F,
1.000000F, -0.164553F, -0.571353F, 0F,
1.000000F, 1.881400F, 0.000000F, 0F,
0F, 0F, 0F, 1F),
new(0F, 0.5F, 0.5F));
new Vector3(0F, 0.5F, 0.5F));
}

4
src/ImageSharp/ColorProfiles/Lms.cs

@ -89,7 +89,7 @@ public readonly struct Lms : IColorProfile<Lms, CieXyz>
v3 += this.AsVector3Unsafe();
v3 += new Vector3(1F);
v3 /= 2F;
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -98,7 +98,7 @@ public readonly struct Lms : IColorProfile<Lms, CieXyz>
Vector3 v3 = source.AsVector3();
v3 *= 2F;
v3 -= new Vector3(1F);
return new(v3);
return new Lms(v3);
}
/// <inheritdoc/>

6
src/ImageSharp/ColorProfiles/Rgb.cs

@ -154,7 +154,7 @@ public readonly struct Rgb : IProfileConnectingSpace<Rgb, CieXyz>
Rgb linear = FromScaledVector4(options.SourceRgbWorkingSpace.Expand(this.ToScaledVector4()));
// Then convert to xyz
return new(Vector3.Transform(linear.AsVector3Unsafe(), GetRgbToCieXyzMatrix(options.SourceRgbWorkingSpace)));
return new CieXyz(Vector3.Transform(linear.AsVector3Unsafe(), GetRgbToCieXyzMatrix(options.SourceRgbWorkingSpace)));
}
/// <inheritdoc/>
@ -171,7 +171,7 @@ public readonly struct Rgb : IProfileConnectingSpace<Rgb, CieXyz>
Rgb linear = FromScaledVector4(options.SourceRgbWorkingSpace.Expand(rgb.ToScaledVector4()));
// Then convert to xyz
destination[i] = new(Vector3.Transform(linear.AsVector3Unsafe(), matrix));
destination[i] = new CieXyz(Vector3.Transform(linear.AsVector3Unsafe(), matrix));
}
}
@ -274,7 +274,7 @@ public readonly struct Rgb : IProfileConnectingSpace<Rgb, CieXyz>
Vector3 vector = Vector3.Transform(workingSpace.WhitePoint.AsVector3Unsafe(), inverseXyzMatrix);
// Use transposed Rows/Columns
return new()
return new Matrix4x4
{
M11 = vector.X * mXr,
M21 = vector.Y * mXg,

6
src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs

@ -31,7 +31,7 @@ public static class VonKriesChromaticAdaptation
if (from.Equals(to))
{
return new(source.X, source.Y, source.Z);
return new CieXyz(source.X, source.Y, source.Z);
}
Vector3 sourceColorLms = Vector3.Transform(source.AsVector3Unsafe(), matrix);
@ -42,7 +42,7 @@ public static class VonKriesChromaticAdaptation
Vector3 targetColorLms = Vector3.Multiply(vector, sourceColorLms);
Matrix4x4.Invert(matrix, out Matrix4x4 inverseMatrix);
return new(Vector3.Transform(targetColorLms, inverseMatrix));
return new CieXyz(Vector3.Transform(targetColorLms, inverseMatrix));
}
/// <summary>
@ -89,7 +89,7 @@ public static class VonKriesChromaticAdaptation
Vector3 sourceColorLms = Vector3.Transform(sp.AsVector3Unsafe(), matrix);
Vector3 targetColorLms = Vector3.Multiply(vector, sourceColorLms);
dp = new(Vector3.Transform(targetColorLms, inverseMatrix));
dp = new CieXyz(Vector3.Transform(targetColorLms, inverseMatrix));
}
}
}

2
src/ImageSharp/ColorProfiles/Y.cs

@ -92,7 +92,7 @@ public readonly struct Y : IColorProfile<Y, Rgb>
{
Matrix4x4 m = options.YCbCrTransform.Forward;
float offset = options.YCbCrTransform.Offset.X;
return new(Vector3.Dot(source.AsVector3Unsafe(), new(m.M11, m.M12, m.M13)) + offset);
return new Y(Vector3.Dot(source.AsVector3Unsafe(), new Vector3(m.M11, m.M12, m.M13)) + offset);
}
/// <inheritdoc/>

6
src/ImageSharp/ColorProfiles/YCbCr.cs

@ -24,7 +24,7 @@ public readonly struct YCbCr : IColorProfile<YCbCr, Rgb>
/// <param name="cr">The cr chroma component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public YCbCr(float y, float cb, float cr)
: this(new(y, cb, cr))
: this(new Vector3(y, cb, cr))
{
}
@ -95,7 +95,7 @@ public readonly struct YCbCr : IColorProfile<YCbCr, Rgb>
{
Vector3 v3 = default;
v3 += this.AsVector3Unsafe();
return new(v3, 1F);
return new Vector4(v3, 1F);
}
/// <inheritdoc/>
@ -133,7 +133,7 @@ public readonly struct YCbCr : IColorProfile<YCbCr, Rgb>
Matrix4x4 m = options.TransposedYCbCrTransform.Forward;
Vector3 offset = options.TransposedYCbCrTransform.Offset;
return new(Vector3.Transform(rgb, m) + offset, true);
return new YCbCr(Vector3.Transform(rgb, m) + offset, true);
}
/// <inheritdoc/>

6
src/ImageSharp/ColorProfiles/YccK.cs

@ -27,7 +27,7 @@ public readonly struct YccK : IColorProfile<YccK, Rgb>
/// <param name="k">The keyline black component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public YccK(float y, float cb, float cr, float k)
: this(new(y, cb, cr, k))
: this(new Vector4(y, cb, cr, k))
{
}
@ -149,11 +149,11 @@ public readonly struct YccK : IColorProfile<YccK, Rgb>
if (k >= 1F - Constants.Epsilon)
{
return new(new(0F, 0.5F, 0.5F, 1F), true);
return new YccK(new Vector4(0F, 0.5F, 0.5F, 1F), true);
}
rgb /= 1F - k;
return new(new Vector4(Vector3.Transform(rgb, m), k) + new Vector4(offset, 0F));
return new YccK(new Vector4(Vector3.Transform(rgb, m), k) + new Vector4(offset, 0F));
}
/// <inheritdoc/>

2
src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs

@ -14,6 +14,6 @@ internal static class ConfigurationExtensions
/// </summary>
public static ParallelOptions GetParallelOptions(this Configuration configuration)
{
return new() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
}
}

2
src/ImageSharp/Common/Helpers/Numerics.cs

@ -656,7 +656,7 @@ internal static class Numerics
return Sse.Shuffle(value.AsVector128(), value.AsVector128(), ShuffleAlphaControl).AsVector4();
}
return new(value.W);
return new Vector4(value.W);
}
/// <summary>

2
src/ImageSharp/Common/Helpers/SimdUtils.Pack.cs

@ -134,7 +134,7 @@ internal static partial class SimdUtils
ref Rgba32 rgb = ref MemoryMarshal.GetReference(destination);
nuint count = (uint)redChannel.Length / 4;
destination.Fill(new(0, 0, 0, 255));
destination.Fill(new Rgba32(0, 0, 0, 255));
for (nuint i = 0; i < count; i++)
{
ref Rgba32 d0 = ref Unsafe.Add(ref rgb, i * 4);

2
src/ImageSharp/Common/Helpers/SimdUtils.cs

@ -29,7 +29,7 @@ internal static partial class SimdUtils
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Vector4 PseudoRound(this Vector4 v)
{
Vector4 sign = Numerics.Clamp(v, new(-1), new(1));
Vector4 sign = Numerics.Clamp(v, new Vector4(-1), new Vector4(1));
return v + (sign * 0.5f);
}

2
src/ImageSharp/Common/Helpers/TolerantMath.cs

@ -20,7 +20,7 @@ internal readonly struct TolerantMath
/// It is a field so it can be passed as an 'in' parameter.
/// Does not necessarily fit all use cases!
/// </summary>
public static readonly TolerantMath Default = new TolerantMath(1e-8);
public static readonly TolerantMath Default = new(1e-8);
public TolerantMath(double epsilon)
{

4
src/ImageSharp/Common/Helpers/UnitConverter.cs

@ -131,9 +131,9 @@ internal static class UnitConverter
ushort exifUnit = (ushort)(unit + 1);
if (unit == PixelResolutionUnit.AspectRatio)
{
return new(exifUnit, null, null);
return new ExifResolutionValues(exifUnit, null, null);
}
return new(exifUnit, horizontal, vertical);
return new ExifResolutionValues(exifUnit, horizontal, vertical);
}
}

2
src/ImageSharp/Compression/Zlib/Deflater.cs

@ -79,7 +79,7 @@ internal sealed class Deflater : IDisposable
}
// TODO: Possibly provide DeflateStrategy as an option.
this.engine = new(memoryAllocator, DeflateStrategy.Default);
this.engine = new DeflaterEngine(memoryAllocator, DeflateStrategy.Default);
this.SetLevel(level);
this.Reset();

2
src/ImageSharp/Compression/Zlib/DeflaterEngine.cs

@ -147,7 +147,7 @@ internal sealed unsafe class DeflaterEngine : IDisposable
/// <param name="strategy">The deflate strategy to use.</param>
public DeflaterEngine(MemoryAllocator memoryAllocator, DeflateStrategy strategy)
{
this.huffman = new(memoryAllocator);
this.huffman = new DeflaterHuffman(memoryAllocator);
this.Pending = this.huffman.Pending;
this.strategy = strategy;

8
src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs

@ -58,11 +58,11 @@ internal sealed unsafe class DeflaterHuffman : IDisposable
/// <param name="memoryAllocator">The memory allocator to use for buffer allocations.</param>
public DeflaterHuffman(MemoryAllocator memoryAllocator)
{
this.Pending = new(memoryAllocator);
this.Pending = new DeflaterPendingBuffer(memoryAllocator);
this.literalTree = new(memoryAllocator, LiteralNumber, 257, 15);
this.distTree = new(memoryAllocator, DistanceNumber, 1, 15);
this.blTree = new(memoryAllocator, BitLengthNumber, 4, 7);
this.literalTree = new Tree(memoryAllocator, LiteralNumber, 257, 15);
this.distTree = new Tree(memoryAllocator, DistanceNumber, 1, 15);
this.blTree = new Tree(memoryAllocator, BitLengthNumber, 4, 7);
this.distanceMemoryOwner = memoryAllocator.Allocate<short>(BufferSize);
this.distanceBufferHandle = this.distanceMemoryOwner.Memory.Pin();

2
src/ImageSharp/Compression/Zlib/DeflaterOutputStream.cs

@ -30,7 +30,7 @@ internal sealed class DeflaterOutputStream : Stream
this.rawStream = rawStream;
this.memoryOwner = memoryAllocator.Allocate<byte>(BufferLength);
this.buffer = this.memoryOwner.Memory;
this.deflater = new(memoryAllocator, compressionLevel);
this.deflater = new Deflater(memoryAllocator, compressionLevel);
}
/// <inheritdoc/>

2
src/ImageSharp/Compression/Zlib/ZlibDeflateStream.cs

@ -101,7 +101,7 @@ internal sealed class ZlibDeflateStream : Stream
this.rawStream.WriteByte(Cmf);
this.rawStream.WriteByte((byte)flg);
this.deflateStream = new(memoryAllocator, this.rawStream, compressionLevel);
this.deflateStream = new DeflaterOutputStream(memoryAllocator, this.rawStream, compressionLevel);
}
/// <inheritdoc/>

2
src/ImageSharp/Compression/Zlib/ZlibInflateStream.cs

@ -270,7 +270,7 @@ internal sealed class ZlibInflateStream : Stream
}
// Initialize the deflate BufferedReadStream.
this.CompressedStream = new(this, CompressionMode.Decompress, true);
this.CompressedStream = new DeflateStream(this, CompressionMode.Decompress, true);
return true;
}

2
src/ImageSharp/Configuration.cs

@ -122,7 +122,7 @@ public sealed class Configuration
/// <summary>
/// Gets or the <see cref="ImageFormatManager"/> that is currently in use.
/// </summary>
public ImageFormatManager ImageFormatsManager { get; private set; } = new ImageFormatManager();
public ImageFormatManager ImageFormatsManager { get; private set; } = new();
/// <summary>
/// Gets or sets the <see cref="Memory.MemoryAllocator"/> that is currently in use.

2
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -25,7 +25,7 @@ public sealed class BmpDecoder : SpecializedImageDecoder<BmpDecoderOptions>
Guard.NotNull(options, nameof(options));
Guard.NotNull(stream, nameof(stream));
return new BmpDecoderCore(new() { GeneralOptions = options }).Identify(options.Configuration, stream, cancellationToken);
return new BmpDecoderCore(new BmpDecoderOptions { GeneralOptions = options }).Identify(options.Configuration, stream, cancellationToken);
}
/// <inheritdoc/>

16
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -132,7 +132,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
{
int bytesPerColorMapEntry = this.ReadImageHeaders(stream, out bool inverted, out byte[] palette);
image = new(this.configuration, this.infoHeader.Width, this.infoHeader.Height, this.metadata);
image = new Image<TPixel>(this.configuration, this.infoHeader.Width, this.infoHeader.Height, this.metadata);
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
@ -220,7 +220,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
{
this.ReadImageHeaders(stream, out _, out _);
return new(new(this.infoHeader.Width, this.infoHeader.Height), this.metadata);
return new ImageInfo(new Size(this.infoHeader.Width, this.infoHeader.Height), this.metadata);
}
/// <summary>
@ -343,7 +343,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
RleSkippedPixelHandling.Transparent => TPixel.FromScaledVector4(Vector4.Zero),
// Default handling for skipped pixels is black (which is what System.Drawing is also doing).
_ => TPixel.FromScaledVector4(new(0.0f, 0.0f, 0.0f, 1.0f)),
_ => TPixel.FromScaledVector4(new Vector4(0.0f, 0.0f, 0.0f, 1.0f)),
};
}
else
@ -404,7 +404,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
RleSkippedPixelHandling.Transparent => TPixel.FromScaledVector4(Vector4.Zero),
// Default handling for skipped pixels is black (which is what System.Drawing is also doing).
_ => TPixel.FromScaledVector4(new(0.0f, 0.0f, 0.0f, 1.0f)),
_ => TPixel.FromScaledVector4(new Vector4(0.0f, 0.0f, 0.0f, 1.0f)),
};
}
else
@ -1270,7 +1270,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
byte g = (byte)((temp & greenMask) >> rightShiftGreenMask);
byte b = (byte)((temp & blueMask) >> rightShiftBlueMask);
byte a = alphaMask != 0 ? (byte)((temp & alphaMask) >> rightShiftAlphaMask) : byte.MaxValue;
pixelRow[x] = TPixel.FromRgba32(new(r, g, b, a));
pixelRow[x] = TPixel.FromRgba32(new Rgba32(r, g, b, a));
}
offset += 4;
@ -1332,7 +1332,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
long infoHeaderStart = stream.Position;
// Resolution is stored in PPM.
this.metadata = new()
this.metadata = new ImageMetadata
{
ResolutionUnits = PixelResolutionUnit.PixelsPerMeter
};
@ -1426,7 +1426,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
byte[] iccProfileData = new byte[this.infoHeader.ProfileSize];
stream.Position = infoHeaderStart + this.infoHeader.ProfileData;
stream.Read(iccProfileData);
this.metadata.IccProfile = new(iccProfileData);
this.metadata.IccProfile = new IccProfile(iccProfileData);
stream.Position = streamPosition;
}
}
@ -1457,7 +1457,7 @@ internal sealed class BmpDecoderCore : ImageDecoderCore
this.bmpMetadata.InfoHeaderType = infoHeaderType;
this.bmpMetadata.BitsPerPixel = (BmpBitsPerPixel)bitsPerPixel;
this.Dimensions = new(this.infoHeader.Width, this.infoHeader.Height);
this.Dimensions = new Size(this.infoHeader.Width, this.infoHeader.Height);
}
/// <summary>

6
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -655,7 +655,7 @@ internal sealed class BmpEncoderCore
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new()
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions
{
MaxColors = 16,
Dither = this.quantizer.Options.Dither,
@ -712,7 +712,7 @@ internal sealed class BmpEncoderCore
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new()
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions
{
MaxColors = 4,
Dither = this.quantizer.Options.Dither,
@ -778,7 +778,7 @@ internal sealed class BmpEncoderCore
CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
{
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new()
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(configuration, new QuantizerOptions
{
MaxColors = 2,
Dither = this.quantizer.Options.Dither,

2
src/ImageSharp/Formats/Bmp/BmpFormat.cs

@ -15,7 +15,7 @@ public sealed class BmpFormat : IImageFormat<BmpMetadata>
/// <summary>
/// Gets the shared instance.
/// </summary>
public static BmpFormat Instance { get; } = new BmpFormat();
public static BmpFormat Instance { get; } = new();
/// <inheritdoc/>
public string Name => "BMP";

16
src/ImageSharp/Formats/Bmp/BmpMetadata.cs

@ -54,21 +54,21 @@ public class BmpMetadata : IFormatMetadata<BmpMetadata>
int bpp = metadata.PixelTypeInfo.BitsPerPixel;
return bpp switch
{
1 => new() { BitsPerPixel = BmpBitsPerPixel.Bit1 },
2 => new() { BitsPerPixel = BmpBitsPerPixel.Bit2 },
<= 4 => new() { BitsPerPixel = BmpBitsPerPixel.Bit4 },
<= 8 => new() { BitsPerPixel = BmpBitsPerPixel.Bit8 },
<= 16 => new()
1 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit1 },
2 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit2 },
<= 4 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit4 },
<= 8 => new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Bit8 },
<= 16 => new BmpMetadata
{
BitsPerPixel = BmpBitsPerPixel.Bit16,
InfoHeaderType = BmpInfoHeaderType.WinVersion3
},
<= 24 => new()
<= 24 => new BmpMetadata
{
BitsPerPixel = BmpBitsPerPixel.Bit24,
InfoHeaderType = BmpInfoHeaderType.WinVersion4
},
_ => new()
_ => new BmpMetadata
{
BitsPerPixel = BmpBitsPerPixel.Bit32,
InfoHeaderType = BmpInfoHeaderType.WinVersion5
@ -131,7 +131,7 @@ public class BmpMetadata : IFormatMetadata<BmpMetadata>
break;
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ComponentInfo = info,

8
src/ImageSharp/Formats/Cur/CurFrameMetadata.cs

@ -73,7 +73,7 @@ public class CurFrameMetadata : IFormatFrameMetadata<CurFrameMetadata>
{
if (!metadata.PixelTypeInfo.HasValue)
{
return new()
return new CurFrameMetadata
{
BmpBitsPerPixel = BmpBitsPerPixel.Bit32,
Compression = IconFrameCompression.Png
@ -98,7 +98,7 @@ public class CurFrameMetadata : IFormatFrameMetadata<CurFrameMetadata>
compression = IconFrameCompression.Png;
}
return new()
return new CurFrameMetadata
{
BmpBitsPerPixel = bbpp,
Compression = compression,
@ -147,7 +147,7 @@ public class CurFrameMetadata : IFormatFrameMetadata<CurFrameMetadata>
? (byte)0
: (byte)ColorNumerics.GetColorCountForBitDepth((int)this.BmpBitsPerPixel);
return new()
return new IconDirEntry
{
Width = ClampEncodingDimension(this.EncodingWidth ?? size.Width),
Height = ClampEncodingDimension(this.EncodingHeight ?? size.Height),
@ -210,7 +210,7 @@ public class CurFrameMetadata : IFormatFrameMetadata<CurFrameMetadata>
}
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ComponentInfo = info,

4
src/ImageSharp/Formats/Cur/CurMetadata.cs

@ -68,7 +68,7 @@ public class CurMetadata : IFormatMetadata<CurMetadata>
compression = IconFrameCompression.Png;
}
return new()
return new CurMetadata
{
BmpBitsPerPixel = bbpp,
Compression = compression
@ -129,7 +129,7 @@ public class CurMetadata : IFormatMetadata<CurMetadata>
}
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ComponentInfo = info,

2
src/ImageSharp/Formats/DecoderOptions.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Formats;
/// </summary>
public sealed class DecoderOptions
{
private static readonly Lazy<DecoderOptions> LazyOptions = new(() => new());
private static readonly Lazy<DecoderOptions> LazyOptions = new(() => new DecoderOptions());
private uint maxFrames = int.MaxValue;

12
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -266,8 +266,8 @@ internal sealed class GifDecoderCore : ImageDecoderCore
GifThrowHelper.ThrowNoHeader();
}
return new(
new(this.logicalScreenDescriptor.Width, this.logicalScreenDescriptor.Height),
return new ImageInfo(
new Size(this.logicalScreenDescriptor.Width, this.logicalScreenDescriptor.Height),
this.metadata,
framesMetadata);
}
@ -305,7 +305,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore
GifThrowHelper.ThrowInvalidImageContentException("Width or height should not be 0");
}
this.Dimensions = new(this.imageDescriptor.Width, this.imageDescriptor.Height);
this.Dimensions = new Size(this.imageDescriptor.Width, this.imageDescriptor.Height);
}
/// <summary>
@ -344,7 +344,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore
GifXmpApplicationExtension extension = GifXmpApplicationExtension.Read(stream, this.memoryAllocator);
if (extension.Data.Length > 0)
{
this.metadata!.XmpProfile = new(extension.Data);
this.metadata!.XmpProfile = new XmpProfile(extension.Data);
}
else
{
@ -554,7 +554,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore
if (previousFrame is null && previousDisposalMode is null)
{
image = transFlag
? new(this.configuration, imageWidth, imageHeight, this.metadata)
? new Image<TPixel>(this.configuration, imageWidth, imageHeight, this.metadata)
: new Image<TPixel>(this.configuration, imageWidth, imageHeight, backgroundPixel, this.metadata);
this.SetFrameMetadata(image.Frames.RootFrame.Metadata);
@ -597,7 +597,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore
if (disposalMethod == FrameDisposalMode.RestoreToBackground)
{
this.restoreArea = Rectangle.Intersect(image.Bounds, new(descriptor.Left, descriptor.Top, descriptor.Width, descriptor.Height));
this.restoreArea = Rectangle.Intersect(image.Bounds, new Rectangle(descriptor.Left, descriptor.Top, descriptor.Width, descriptor.Height));
}
if (colorTable.Length == 0)

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

@ -113,7 +113,7 @@ internal sealed class GifEncoderCore
TransparentColorMode mode = this.transparentColorMode;
// Create a new quantizer options instance augmenting the transparent color mode to match the encoder.
QuantizerOptions options = (this.encoder.Quantizer?.Options ?? new()).DeepClone(o => o.TransparentColorMode = mode);
QuantizerOptions options = (this.encoder.Quantizer?.Options ?? new QuantizerOptions()).DeepClone(o => o.TransparentColorMode = mode);
if (globalQuantizer is null)
{

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

@ -93,7 +93,7 @@ public class GifFrameMetadata : IFormatFrameMetadata<GifFrameMetadata>
// If the color table is global and frame has no transparency. Consider it 'Source' also.
blendSource |= this.ColorTableMode == FrameColorTableMode.Global && !this.HasTransparency;
return new()
return new FormatConnectingFrameMetadata
{
ColorTableMode = this.ColorTableMode,
Duration = TimeSpan.FromMilliseconds(this.FrameDelay * 10),

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

@ -87,7 +87,7 @@ public class GifMetadata : IFormatMetadata<GifMetadata>
? Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.GlobalColorTable.Value.Length), 1, 8)
: 8;
return new(bpp)
return new PixelTypeInfo(bpp)
{
ColorType = PixelColorType.Indexed,
ComponentInfo = PixelComponentInfo.Create(1, bpp, bpp),

2
src/ImageSharp/Formats/Gif/Sections/GifNetscapeLoopingApplicationExtension.cs

@ -22,7 +22,7 @@ internal readonly struct GifNetscapeLoopingApplicationExtension : IGifExtension
public static GifNetscapeLoopingApplicationExtension Parse(ReadOnlySpan<byte> buffer)
{
ushort repeatCount = BinaryPrimitives.ReadUInt16LittleEndian(buffer[..2]);
return new(repeatCount);
return new GifNetscapeLoopingApplicationExtension(repeatCount);
}
public int WriteTo(Span<byte> buffer)

2
src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs

@ -42,7 +42,7 @@ internal readonly struct GifXmpApplicationExtension : IGifExtension
stream.Skip(1); // Skip the terminator.
}
return new(buffer);
return new GifXmpApplicationExtension(buffer);
}
public int WriteTo(Span<byte> buffer)

8
src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs

@ -66,7 +66,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata<IcoFrameMetadata>
{
if (!metadata.PixelTypeInfo.HasValue)
{
return new()
return new IcoFrameMetadata
{
BmpBitsPerPixel = BmpBitsPerPixel.Bit32,
Compression = IconFrameCompression.Png
@ -91,7 +91,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata<IcoFrameMetadata>
compression = IconFrameCompression.Png;
}
return new()
return new IcoFrameMetadata
{
BmpBitsPerPixel = bbpp,
Compression = compression,
@ -138,7 +138,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata<IcoFrameMetadata>
? (byte)0
: (byte)ColorNumerics.GetColorCountForBitDepth((int)this.BmpBitsPerPixel);
return new()
return new IconDirEntry
{
Width = ClampEncodingDimension(this.EncodingWidth ?? size.Width),
Height = ClampEncodingDimension(this.EncodingHeight ?? size.Height),
@ -205,7 +205,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata<IcoFrameMetadata>
}
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ComponentInfo = info,

4
src/ImageSharp/Formats/Ico/IcoMetadata.cs

@ -68,7 +68,7 @@ public class IcoMetadata : IFormatMetadata<IcoMetadata>
compression = IconFrameCompression.Png;
}
return new()
return new IcoMetadata
{
BmpBitsPerPixel = bbpp,
Compression = compression
@ -129,7 +129,7 @@ public class IcoMetadata : IFormatMetadata<IcoMetadata>
}
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ComponentInfo = info,

12
src/ImageSharp/Formats/Icon/IconDecoderCore.cs

@ -63,7 +63,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore
// Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data
// which technically allows storing icons with larger than 256 pixels, but such larger sizes are not recommended by Microsoft.
this.Dimensions = new(Math.Max(this.Dimensions.Width, temp.Size.Width), Math.Max(this.Dimensions.Height, temp.Size.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, temp.Size.Width), Math.Max(this.Dimensions.Height, temp.Size.Height));
}
ImageMetadata metadata = new();
@ -208,7 +208,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore
// Since Windows Vista, the size of an image is determined from the BITMAPINFOHEADER structure or PNG image data
// which technically allows storing icons with larger than 256 pixels, but such larger sizes are not recommended by Microsoft.
this.Dimensions = new(Math.Max(this.Dimensions.Width, frameInfo.Size.Width), Math.Max(this.Dimensions.Height, frameInfo.Size.Height));
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, frameInfo.Size.Width), Math.Max(this.Dimensions.Height, frameInfo.Size.Height));
}
// Copy the format specific metadata to the image.
@ -222,7 +222,7 @@ internal abstract class IconDecoderCore : ImageDecoderCore
metadata.SetFormatMetadata(PngFormat.Instance, pngMetadata);
}
return new(this.Dimensions, metadata, frames);
return new ImageInfo(this.Dimensions, metadata, frames);
}
protected abstract void SetFrameMetadata(
@ -276,20 +276,20 @@ internal abstract class IconDecoderCore : ImageDecoderCore
height = Math.Max(height, entry.Height);
}
this.Dimensions = new(width, height);
this.Dimensions = new Size(width, height);
}
private ImageDecoderCore GetDecoder(bool isPng)
{
if (isPng)
{
return new PngDecoderCore(new()
return new PngDecoderCore(new PngDecoderOptions
{
GeneralOptions = this.Options,
});
}
return new BmpDecoderCore(new()
return new BmpDecoderCore(new BmpDecoderOptions
{
GeneralOptions = this.Options,
ProcessedAlphaMask = true,

6
src/ImageSharp/Formats/Icon/IconEncoderCore.cs

@ -116,7 +116,7 @@ internal abstract class IconEncoderCore
[MemberNotNull(nameof(entries))]
private void InitHeader(Image image)
{
this.fileHeader = new(this.iconFileType, (ushort)image.Frames.Count);
this.fileHeader = new IconDir(this.iconFileType, (ushort)image.Frames.Count);
this.entries = this.iconFileType switch
{
IconFileType.ICO =>
@ -155,14 +155,14 @@ internal abstract class IconEncoderCore
count = 256;
}
return new WuQuantizer(new()
return new WuQuantizer(new QuantizerOptions
{
MaxColors = count
});
}
// Don't dither if we have a palette. We want to preserve as much information as possible.
return new PaletteQuantizer(metadata.ColorTable.Value, new() { Dither = null });
return new PaletteQuantizer(metadata.ColorTable.Value, new QuantizerOptions { Dither = null });
}
internal sealed class EncodingFrameMetadata

2
src/ImageSharp/Formats/ImageFormatManager.cs

@ -161,7 +161,7 @@ public class ImageFormatManager
/// <summary>
/// Removes all the registered image format detectors.
/// </summary>
public void ClearImageFormatDetectors() => this.imageFormatDetectors = new();
public void ClearImageFormatDetectors() => this.imageFormatDetectors = new ConcurrentBag<IImageFormatDetector>();
/// <summary>
/// Adds a new detector for detecting mime types.

2
src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs

@ -140,7 +140,7 @@ internal partial struct Block8x8
/// <inheritdoc />
public override string ToString()
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();
sb.Append('[');
for (int i = 0; i < Size; i++)
{

8
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs

@ -57,19 +57,19 @@ internal partial struct Block8x8F
ref Vector4 dTopLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset));
ref Vector4 dBottomLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset + destStride));
Vector4 xyLeft = new Vector4(sLeft.X);
Vector4 xyLeft = new(sLeft.X);
xyLeft.Z = sLeft.Y;
xyLeft.W = sLeft.Y;
Vector4 zwLeft = new Vector4(sLeft.Z);
Vector4 zwLeft = new(sLeft.Z);
zwLeft.Z = sLeft.W;
zwLeft.W = sLeft.W;
Vector4 xyRight = new Vector4(sRight.X);
Vector4 xyRight = new(sRight.X);
xyRight.Z = sRight.Y;
xyRight.W = sRight.Y;
Vector4 zwRight = new Vector4(sRight.Z);
Vector4 zwRight = new(sRight.Z);
zwRight.Z = sRight.W;
zwRight.W = sRight.W;

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.TiffYccKScalar.cs

@ -128,7 +128,7 @@ internal abstract partial class JpegColorConverterBase
ColorProfileConverter converter = new();
Span<Cmyk> source = MemoryMarshal.Cast<float, Cmyk>(packed);
// YccK is not a defined ICC color space it's a JPEG-specific encoding used in Adobe-style CMYK JPEGs.
// YccK is not a defined ICC color space it's a JPEG-specific encoding used in Adobe-style CMYK JPEGs.
// ICC profiles expect colorimetric CMYK values, so we must first convert YccK to CMYK using a hardcoded inverse transform.
// This transform assumes Rec.601 YCbCr coefficients and an inverted K channel.
//
@ -144,7 +144,7 @@ internal abstract partial class JpegColorConverterBase
SourceIccProfile = profile,
TargetIccProfile = CompactSrgbV4Profile.Profile,
};
converter = new(options);
converter = new ColorProfileConverter(options);
converter.Convert<Cmyk, Rgb>(source, destination);
UnpackDeinterleave3(MemoryMarshal.Cast<float, Vector3>(packed)[..source.Length], c0, c1, c2);

2
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrScalar.cs

@ -91,7 +91,7 @@ internal abstract partial class JpegColorConverterBase
SourceIccProfile = profile,
TargetIccProfile = CompactSrgbV4Profile.Profile,
};
converter = new(options);
converter = new ColorProfileConverter(options);
converter.Convert<Rgb, Rgb>(destination, destination);
UnpackDeinterleave3(MemoryMarshal.Cast<float, Vector3>(packed)[..source.Length], c0, c1, c2);

2
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKScalar.cs

@ -116,7 +116,7 @@ internal abstract partial class JpegColorConverterBase
SourceIccProfile = profile,
TargetIccProfile = CompactSrgbV4Profile.Profile,
};
converter = new(options);
converter = new ColorProfileConverter(options);
converter.Convert<Cmyk, Rgb>(source, destination);
UnpackDeinterleave3(MemoryMarshal.Cast<float, Vector3>(packed)[..source.Length], c0, c1, c2);

2
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs

@ -514,7 +514,7 @@ internal abstract partial class JpegColorConverterBase
Span<float> c2 = this.Component2.Length > 0 ? this.Component2.Slice(start, length) : [];
Span<float> c3 = this.Component3.Length > 0 ? this.Component3.Slice(start, length) : [];
return new(this.ComponentCount, c0, c1, c2, c3);
return new ComponentValues(this.ComponentCount, c0, c1, c2, c3);
}
}
}

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/AdobeMarker.cs

@ -71,7 +71,7 @@ internal readonly struct AdobeMarker : IEquatable<AdobeMarker>
short app14Flags1 = (short)((bytes[9] << 8) | bytes[10]);
byte colorTransform = bytes[11];
marker = new(dctEncodeVersion, app14Flags0, app14Flags1, colorTransform);
marker = new AdobeMarker(dctEncodeVersion, app14Flags0, app14Flags1, colorTransform);
return true;
}

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs

@ -242,7 +242,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
this.scanComponentCount = scanComponentCount;
this.scanBuffer = new(this.stream);
this.scanBuffer = new JpegBitReader(this.stream);
this.frame.AllocateComponents();

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

@ -116,7 +116,7 @@ internal class HuffmanScanDecoder : IJpegScanDecoder
this.scanComponentCount = scanComponentCount;
this.scanBuffer = new(this.stream);
this.scanBuffer = new JpegBitReader(this.stream);
this.frame.AllocateComponents();
@ -784,6 +784,6 @@ internal class HuffmanScanDecoder : IJpegScanDecoder
public void BuildHuffmanTable(int type, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values, Span<uint> workspace)
{
HuffmanTable[] tables = type == 0 ? this.dcHuffmanTables : this.acHuffmanTables;
tables[index] = new(codeLengths, values, workspace);
tables[index] = new HuffmanTable(codeLengths, values, workspace);
}
}

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/JFifMarker.cs

@ -80,7 +80,7 @@ internal readonly struct JFifMarker : IEquatable<JFifMarker>
byte densityUnits = bytes[7];
short xDensity = (short)((bytes[8] << 8) | bytes[9]);
short yDensity = (short)((bytes[10] << 8) | bytes[11]);
marker = new(majorVersion, minorVersion, densityUnits, xDensity, yDensity);
marker = new JFifMarker(majorVersion, minorVersion, densityUnits, xDensity, yDensity);
return true;
}

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs

@ -21,7 +21,7 @@ internal class JpegComponent : IDisposable, IJpegComponent
this.HorizontalSamplingFactor = horizontalFactor;
this.VerticalSamplingFactor = verticalFactor;
this.SamplingFactors = new(this.HorizontalSamplingFactor, this.VerticalSamplingFactor);
this.SamplingFactors = new Size(this.HorizontalSamplingFactor, this.VerticalSamplingFactor);
this.QuantizationTableIndex = quantizationTableIndex;
this.Index = index;
@ -109,7 +109,7 @@ internal class JpegComponent : IDisposable, IJpegComponent
int blocksPerLineForMcu = this.Frame.McusPerLine * this.HorizontalSamplingFactor;
int blocksPerColumnForMcu = this.Frame.McusPerColumn * this.VerticalSamplingFactor;
this.SizeInBlocks = new(blocksPerLineForMcu, blocksPerColumnForMcu);
this.SizeInBlocks = new Size(blocksPerLineForMcu, blocksPerColumnForMcu);
this.SubSamplingDivisors = new Size(maxSubFactorH, maxSubFactorV).DivideBy(this.SamplingFactors);

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter.cs

@ -121,7 +121,7 @@ internal abstract class SpectralConverter
if (scaledWidth >= tSize.Width && scaledHeight >= tSize.Height)
{
blockPixelSize = blockSize;
return new(scaledWidth, scaledHeight);
return new Size(scaledWidth, scaledHeight);
}
}
}

4
src/ImageSharp/Formats/Jpeg/Components/Encoder/Component.cs

@ -19,7 +19,7 @@ internal class Component : IDisposable
this.HorizontalSamplingFactor = horizontalFactor;
this.VerticalSamplingFactor = verticalFactor;
this.SamplingFactors = new(horizontalFactor, verticalFactor);
this.SamplingFactors = new Size(horizontalFactor, verticalFactor);
this.QuantizationTableIndex = quantizationTableIndex;
}
@ -95,7 +95,7 @@ internal class Component : IDisposable
int blocksPerLineForMcu = frame.McusPerLine * this.HorizontalSamplingFactor;
int blocksPerColumnForMcu = frame.McusPerColumn * this.VerticalSamplingFactor;
this.SizeInBlocks = new(blocksPerLineForMcu, blocksPerColumnForMcu);
this.SizeInBlocks = new Size(blocksPerLineForMcu, blocksPerColumnForMcu);
this.SubSamplingDivisors = new Size(maxSubFactorH, maxSubFactorV).DivideBy(this.SamplingFactors);

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

@ -241,7 +241,7 @@ internal class ComponentProcessor : IDisposable
ref Vector<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target));
nuint count = target.VectorCount<float>();
Vector<float> multiplierVector = new Vector<float>(multiplier);
Vector<float> multiplierVector = new(multiplier);
for (nuint i = 0; i < count; i++)
{
Unsafe.Add(ref targetVectorRef, i) *= multiplierVector;

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

@ -134,7 +134,7 @@ internal class HuffmanScanEncoder
public void BuildHuffmanTable(JpegHuffmanTableConfig tableConfig)
{
HuffmanLut[] tables = tableConfig.Class == 0 ? this.dcHuffmanTables : this.acHuffmanTables;
tables[tableConfig.DestinationIndex] = new(tableConfig.Table);
tables[tableConfig.DestinationIndex] = new HuffmanLut(tableConfig.Table);
}
/// <summary>

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/JpegFrame.cs

@ -27,7 +27,7 @@ internal sealed class JpegFrame : IDisposable
for (int i = 0; i < this.Components.Length; i++)
{
JpegComponentConfig componentConfig = componentConfigs[i];
this.Components[i] = new(allocator, componentConfig.HorizontalSampleFactor, componentConfig.VerticalSampleFactor, componentConfig.QuantizatioTableIndex)
this.Components[i] = new Component(allocator, componentConfig.HorizontalSampleFactor, componentConfig.VerticalSampleFactor, componentConfig.QuantizatioTableIndex)
{
DcTableId = componentConfig.DcTableSelector,
AcTableId = componentConfig.AcTableSelector,

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs

@ -51,7 +51,7 @@ internal class SpectralConverter<TPixel> : SpectralConverter, IDisposable
for (int i = 0; i < this.componentProcessors.Length; i++)
{
Component component = frame.Components[i];
this.componentProcessors[i] = new(
this.componentProcessors[i] = new ComponentProcessor(
allocator,
component,
postProcessorBufferSize,

2
src/ImageSharp/Formats/Jpeg/Components/SizeExtensions.cs

@ -32,7 +32,7 @@ internal static class SizeExtensions
sizeVect.X = MathF.Ceiling(sizeVect.X);
sizeVect.Y = MathF.Ceiling(sizeVect.Y);
return new((int)sizeVect.X, (int)sizeVect.Y);
return new Size((int)sizeVect.X, (int)sizeVect.Y);
}
/// <summary>

2
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -25,7 +25,7 @@ public sealed class JpegDecoder : SpecializedImageDecoder<JpegDecoderOptions>
Guard.NotNull(options, nameof(options));
Guard.NotNull(stream, nameof(stream));
using JpegDecoderCore decoder = new(new() { GeneralOptions = options });
using JpegDecoderCore decoder = new(new JpegDecoderOptions { GeneralOptions = options });
return decoder.Identify(options.Configuration, stream, cancellationToken);
}

34
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -167,7 +167,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
int b = stream.ReadByte();
if (b == -1)
{
return new(JpegConstants.Markers.EOI, stream.Length - 2);
return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
}
// Found a marker.
@ -179,14 +179,14 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
b = stream.ReadByte();
if (b == -1)
{
return new(JpegConstants.Markers.EOI, stream.Length - 2);
return new JpegFileMarker(JpegConstants.Markers.EOI, stream.Length - 2);
}
}
// Found a valid marker. Exit loop
if (b is not 0 and (< JpegConstants.Markers.RST0 or > JpegConstants.Markers.RST7))
{
return new((byte)(uint)b, stream.Position - 2);
return new JpegFileMarker((byte)(uint)b, stream.Position - 2);
}
}
}
@ -205,7 +205,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
_ = this.Options.TryGetIccProfileForColorConversion(this.Metadata.IccProfile, out IccProfile profile);
return new(
return new Image<TPixel>(
this.configuration,
spectralConverter.GetPixelBuffer(profile, cancellationToken),
this.Metadata);
@ -222,7 +222,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
this.InitDerivedMetadataProperties();
Size pixelSize = this.Frame.PixelSize;
return new(new(pixelSize.Width, pixelSize.Height), this.Metadata);
return new ImageInfo(new Size(pixelSize.Width, pixelSize.Height), this.Metadata);
}
/// <summary>
@ -233,7 +233,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
/// <param name="scanDecoder">The scan decoder.</param>
public void LoadTables(byte[] tableBytes, IJpegScanDecoder scanDecoder)
{
this.Metadata ??= new();
this.Metadata ??= new ImageMetadata();
this.QuantizationTables = new Block8x8F[4];
this.scanDecoder = scanDecoder;
if (tableBytes.Length < 4)
@ -256,7 +256,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
// Read next marker.
bytesRead = stream.Read(markerBuffer);
fileMarker = new(markerBuffer[1], (int)stream.Position - 2);
fileMarker = new JpegFileMarker(markerBuffer[1], (int)stream.Position - 2);
while (fileMarker.Marker != JpegConstants.Markers.EOI || (fileMarker.Marker == JpegConstants.Markers.EOI && fileMarker.Invalid))
{
@ -300,7 +300,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
JpegThrowHelper.ThrowInvalidImageContentException("Not enough data to read marker");
}
fileMarker = new(markerBuffer[1], 0);
fileMarker = new JpegFileMarker(markerBuffer[1], 0);
}
}
@ -316,7 +316,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
this.scanDecoder ??= new HuffmanScanDecoder(stream, spectralConverter, cancellationToken);
this.Metadata ??= new();
this.Metadata ??= new ImageMetadata();
Span<byte> markerBuffer = stackalloc byte[2];
@ -529,7 +529,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
chars[i] = (char)read;
}
metadata.Comments.Add(new(chars));
metadata.Comments.Add(new JpegComData(chars));
}
/// <summary>
@ -661,7 +661,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
{
if (this.hasExif)
{
this.Metadata.ExifProfile = new(this.exifData);
this.Metadata.ExifProfile = new ExifProfile(this.exifData);
}
}
@ -685,7 +685,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
if (!this.skipMetadata && profile?.CheckIsValid() == true)
{
this.hasIcc = true;
this.Metadata ??= new();
this.Metadata ??= new ImageMetadata();
this.Metadata.IccProfile = profile;
}
}
@ -697,7 +697,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
{
if (this.hasIptc)
{
this.Metadata.IptcProfile = new(this.iptcData);
this.Metadata.IptcProfile = new IptcProfile(this.iptcData);
}
}
@ -708,7 +708,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
{
if (this.hasXmp)
{
this.Metadata.XmpProfile = new(this.xmpData);
this.Metadata.XmpProfile = new XmpProfile(this.xmpData);
}
}
@ -992,7 +992,7 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
/// <param name="remaining">The remaining bytes in the segment block.</param>
private void ProcessArithmeticTable(BufferedReadStream stream, int remaining)
{
this.arithmeticDecodingTables ??= new(4);
this.arithmeticDecodingTables ??= new List<ArithmeticDecodingTable>(4);
while (remaining > 0)
{
@ -1242,8 +1242,8 @@ internal sealed class JpegDecoderCore : ImageDecoderCore, IRawJpegData
JpegThrowHelper.ThrowNotSupportedComponentCount(componentCount);
}
this.Frame = new(frameMarker, precision, frameWidth, frameHeight, componentCount);
this.Dimensions = new(frameWidth, frameHeight);
this.Frame = new JpegFrame(frameMarker, precision, frameWidth, frameHeight, componentCount);
this.Dimensions = new Size(frameWidth, frameHeight);
this.Metadata.GetJpegMetadata().Progressive = this.Frame.Progressive;
remaining -= length;

84
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.FrameConfig.cs

@ -13,13 +13,13 @@ internal sealed unsafe partial class JpegEncoderCore
{
private static JpegFrameConfig[] CreateFrameConfigs()
{
JpegHuffmanTableConfig defaultLuminanceHuffmanDC = new JpegHuffmanTableConfig(@class: 0, destIndex: 0, HuffmanSpec.LuminanceDC);
JpegHuffmanTableConfig defaultLuminanceHuffmanAC = new JpegHuffmanTableConfig(@class: 1, destIndex: 0, HuffmanSpec.LuminanceAC);
JpegHuffmanTableConfig defaultChrominanceHuffmanDC = new JpegHuffmanTableConfig(@class: 0, destIndex: 1, HuffmanSpec.ChrominanceDC);
JpegHuffmanTableConfig defaultChrominanceHuffmanAC = new JpegHuffmanTableConfig(@class: 1, destIndex: 1, HuffmanSpec.ChrominanceAC);
JpegHuffmanTableConfig defaultLuminanceHuffmanDC = new(@class: 0, destIndex: 0, HuffmanSpec.LuminanceDC);
JpegHuffmanTableConfig defaultLuminanceHuffmanAC = new(@class: 1, destIndex: 0, HuffmanSpec.LuminanceAC);
JpegHuffmanTableConfig defaultChrominanceHuffmanDC = new(@class: 0, destIndex: 1, HuffmanSpec.ChrominanceDC);
JpegHuffmanTableConfig defaultChrominanceHuffmanAC = new(@class: 1, destIndex: 1, HuffmanSpec.ChrominanceAC);
JpegQuantizationTableConfig defaultLuminanceQuantTable = new JpegQuantizationTableConfig(0, Quantization.LuminanceTable);
JpegQuantizationTableConfig defaultChrominanceQuantTable = new JpegQuantizationTableConfig(1, Quantization.ChrominanceTable);
JpegQuantizationTableConfig defaultLuminanceQuantTable = new(0, Quantization.LuminanceTable);
JpegQuantizationTableConfig defaultChrominanceQuantTable = new(1, Quantization.ChrominanceTable);
JpegHuffmanTableConfig[] yCbCrHuffmanConfigs = new JpegHuffmanTableConfig[]
{
@ -38,77 +38,77 @@ internal sealed unsafe partial class JpegEncoderCore
return new JpegFrameConfig[]
{
// YCbCr 4:4:4
new JpegFrameConfig(
new(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio444,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:2:2
new JpegFrameConfig(
new(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio422,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 1, hsf: 2, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:2:0
new JpegFrameConfig(
new(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio420,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 1, hsf: 2, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:1:1
new JpegFrameConfig(
new(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio411,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 1, hsf: 4, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// YCbCr 4:1:0
new JpegFrameConfig(
new(
JpegColorSpace.YCbCr,
JpegColorType.YCbCrRatio410,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 1, hsf: 4, vsf: 2, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 1, dcIndex: 1, acIndex: 1),
},
yCbCrHuffmanConfigs,
yCbCrQuantTableConfigs),
// Luminance
new JpegFrameConfig(
new(
JpegColorSpace.Grayscale,
JpegColorType.Luminance,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 0, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
@ -121,14 +121,14 @@ internal sealed unsafe partial class JpegEncoderCore
}),
// Rgb
new JpegFrameConfig(
new(
JpegColorSpace.RGB,
JpegColorType.Rgb,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 82, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 71, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 66, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
@ -144,15 +144,15 @@ internal sealed unsafe partial class JpegEncoderCore
},
// Cmyk
new JpegFrameConfig(
new(
JpegColorSpace.Cmyk,
JpegColorType.Cmyk,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{
@ -168,15 +168,15 @@ internal sealed unsafe partial class JpegEncoderCore
},
// YccK
new JpegFrameConfig(
new(
JpegColorSpace.Ycck,
JpegColorType.Ycck,
new JpegComponentConfig[]
{
new JpegComponentConfig(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new JpegComponentConfig(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 1, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 2, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 3, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
new(id: 4, hsf: 1, vsf: 1, quantIndex: 0, dcIndex: 0, acIndex: 0),
},
new JpegHuffmanTableConfig[]
{

2
src/ImageSharp/Formats/Jpeg/JpegFormat.cs

@ -15,7 +15,7 @@ public sealed class JpegFormat : IImageFormat<JpegMetadata>
/// <summary>
/// Gets the shared instance.
/// </summary>
public static JpegFormat Instance { get; } = new JpegFormat();
public static JpegFormat Instance { get; } = new();
/// <inheritdoc/>
public string Name => "JPEG";

4
src/ImageSharp/Formats/Jpeg/JpegMetadata.cs

@ -139,7 +139,7 @@ public class JpegMetadata : IFormatMetadata<JpegMetadata>
break;
}
return new()
return new JpegMetadata
{
ColorType = color,
ChrominanceQuality = metadata.Quality,
@ -182,7 +182,7 @@ public class JpegMetadata : IFormatMetadata<JpegMetadata>
break;
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = PixelAlphaRepresentation.None,
ColorType = colorType,

8
src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs

@ -79,8 +79,8 @@ internal sealed class PbmDecoderCore : ImageDecoderCore
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
{
this.ProcessHeader(stream);
return new(
new(this.pixelSize.Width, this.pixelSize.Height),
return new ImageInfo(
new Size(this.pixelSize.Width, this.pixelSize.Height),
this.metadata);
}
@ -171,9 +171,9 @@ internal sealed class PbmDecoderCore : ImageDecoderCore
this.componentType = PbmComponentType.Bit;
}
this.pixelSize = new(width, height);
this.pixelSize = new Size(width, height);
this.Dimensions = this.pixelSize;
this.metadata = new();
this.metadata = new ImageMetadata();
PbmMetadata meta = this.metadata.GetPbmMetadata();
meta.Encoding = this.encoding;
meta.ColorType = this.colorType;

4
src/ImageSharp/Formats/Pbm/PbmMetadata.cs

@ -77,7 +77,7 @@ public class PbmMetadata : IFormatMetadata<PbmMetadata>
_ => PbmComponentType.Short
};
return new()
return new PbmMetadata
{
ColorType = color,
ComponentType = componentType
@ -114,7 +114,7 @@ public class PbmMetadata : IFormatMetadata<PbmMetadata>
break;
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = PixelAlphaRepresentation.None,
ColorType = colorType,

8
src/ImageSharp/Formats/Pbm/PlainDecoder.cs

@ -71,7 +71,7 @@ internal class PlainDecoder
for (int x = 0; x < width; x++)
{
stream.ReadDecimal(out int value);
rowSpan[x] = new((byte)value);
rowSpan[x] = new L8((byte)value);
eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
@ -107,7 +107,7 @@ internal class PlainDecoder
for (int x = 0; x < width; x++)
{
stream.ReadDecimal(out int value);
rowSpan[x] = new((ushort)value);
rowSpan[x] = new L16((ushort)value);
eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
@ -154,7 +154,7 @@ internal class PlainDecoder
stream.ReadDecimal(out int blue);
rowSpan[x] = new((byte)red, (byte)green, (byte)blue);
rowSpan[x] = new Rgb24((byte)red, (byte)green, (byte)blue);
eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
@ -201,7 +201,7 @@ internal class PlainDecoder
stream.ReadDecimal(out int blue);
rowSpan[x] = new((ushort)red, (ushort)green, (ushort)blue);
rowSpan[x] = new Rgb48((ushort)red, (ushort)green, (ushort)blue);
eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{

4
src/ImageSharp/Formats/Png/Chunks/PngPhysical.cs

@ -50,7 +50,7 @@ internal readonly struct PngPhysical
uint vResolution = BinaryPrimitives.ReadUInt32BigEndian(data.Slice(4, 4));
byte unit = data[8];
return new(hResolution, vResolution, unit);
return new PngPhysical(hResolution, vResolution, unit);
}
/// <summary>
@ -92,7 +92,7 @@ internal readonly struct PngPhysical
break;
}
return new(x, y, unitSpecifier);
return new PngPhysical(x, y, unitSpecifier);
}
/// <summary>

2
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -25,7 +25,7 @@ public sealed class PngDecoder : SpecializedImageDecoder<PngDecoderOptions>
Guard.NotNull(options, nameof(options));
Guard.NotNull(stream, nameof(stream));
return new PngDecoderCore(new() { GeneralOptions = options }).Identify(options.Configuration, stream, cancellationToken);
return new PngDecoderCore(new PngDecoderOptions { GeneralOptions = options }).Identify(options.Configuration, stream, cancellationToken);
}
/// <inheritdoc/>

34
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -248,7 +248,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
break;
case PngChunkType.Data:
pngMetadata.AnimateRootFrame = currentFrameControl != null;
currentFrameControl ??= new((uint)this.header.Width, (uint)this.header.Height);
currentFrameControl ??= new FrameControl((uint)this.header.Width, (uint)this.header.Height);
if (image is null)
{
this.InitializeImage(metadata, currentFrameControl.Value, out image);
@ -297,7 +297,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
{
byte[] exifData = new byte[chunk.Length];
chunk.Data.GetSpan().CopyTo(exifData);
MergeOrSetExifProfile(metadata, new(exifData), replaceExistingKeys: true);
MergeOrSetExifProfile(metadata, new ExifProfile(exifData), replaceExistingKeys: true);
}
break;
@ -433,7 +433,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
}
pngMetadata.AnimateRootFrame = currentFrameControl != null;
currentFrameControl ??= new((uint)this.header.Width, (uint)this.header.Height);
currentFrameControl ??= new FrameControl((uint)this.header.Width, (uint)this.header.Height);
if (framesMetadata.Count == 0)
{
InitializeFrameMetadata(framesMetadata, currentFrameControl.Value);
@ -497,7 +497,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
{
byte[] exifData = new byte[chunk.Length];
chunk.Data.GetSpan().CopyTo(exifData);
MergeOrSetExifProfile(metadata, new(exifData), replaceExistingKeys: true);
MergeOrSetExifProfile(metadata, new ExifProfile(exifData), replaceExistingKeys: true);
}
break;
@ -525,7 +525,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
PngThrowHelper.ThrowInvalidHeader();
}
return new(new(this.header.Width, this.header.Height), metadata, framesMetadata);
return new ImageInfo(new Size(this.header.Width, this.header.Height), metadata, framesMetadata);
}
finally
{
@ -626,7 +626,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
private void InitializeImage<TPixel>(ImageMetadata metadata, FrameControl frameControl, out Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
{
image = new(this.configuration, this.header.Width, this.header.Height, metadata);
image = new Image<TPixel>(this.configuration, this.header.Width, this.header.Height, metadata);
PngFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetPngMetadata();
frameMetadata.FromChunk(in frameControl);
@ -1343,7 +1343,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
pngMetadata.InterlaceMethod = this.header.InterlaceMethod;
this.pngColorType = this.header.ColorType;
this.Dimensions = new(this.header.Width, this.header.Height);
this.Dimensions = new Size(this.header.Width, this.header.Height);
}
/// <summary>
@ -1377,7 +1377,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
if (!TryReadTextChunkMetadata(baseMetadata, name, value))
{
metadata.TextData.Add(new(name, value, string.Empty, string.Empty));
metadata.TextData.Add(new PngTextData(name, value, string.Empty, string.Empty));
}
}
@ -1418,7 +1418,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
if (this.TryDecompressTextData(compressedData, PngConstants.Encoding, out string? uncompressed)
&& !TryReadTextChunkMetadata(baseMetadata, name, uncompressed))
{
metadata.TextData.Add(new(name, uncompressed, string.Empty, string.Empty));
metadata.TextData.Add(new PngTextData(name, uncompressed, string.Empty, string.Empty));
}
}
@ -1476,7 +1476,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
fullRange = null;
}
metadata.CicpProfile = new(colorPrimaries, transferFunction, matrixCoefficients, fullRange);
metadata.CicpProfile = new CicpProfile(colorPrimaries, transferFunction, matrixCoefficients, fullRange);
}
/// <summary>
@ -1560,7 +1560,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
return false;
}
MergeOrSetExifProfile(metadata, new(exifBlob), replaceExistingKeys: false);
MergeOrSetExifProfile(metadata, new ExifProfile(exifBlob), replaceExistingKeys: false);
return true;
}
@ -1594,7 +1594,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
if (this.TryDecompressZlibData(compressedData, this.maxUncompressedLength, out byte[] iccpProfileBytes))
{
metadata.IccProfile = new(iccpProfileBytes);
metadata.IccProfile = new IccProfile(iccpProfileBytes);
}
}
@ -1750,17 +1750,17 @@ internal sealed class PngDecoderCore : ImageDecoderCore
if (this.TryDecompressTextData(compressedData, PngConstants.TranslatedEncoding, out string? uncompressed))
{
pngMetadata.TextData.Add(new(keyword, uncompressed, language, translatedKeyword));
pngMetadata.TextData.Add(new PngTextData(keyword, uncompressed, language, translatedKeyword));
}
}
else if (IsXmpTextData(keywordBytes))
{
metadata.XmpProfile = new(data[dataStartIdx..].ToArray());
metadata.XmpProfile = new XmpProfile(data[dataStartIdx..].ToArray());
}
else
{
string value = PngConstants.TranslatedEncoding.GetString(data[dataStartIdx..]);
pngMetadata.TextData.Add(new(keyword, value, language, translatedKeyword));
pngMetadata.TextData.Add(new PngTextData(keyword, value, language, translatedKeyword));
}
}
@ -1950,14 +1950,14 @@ internal sealed class PngDecoderCore : ImageDecoderCore
type != PngChunkType.AnimationControl &&
type != PngChunkType.FrameControl)
{
chunk = new(length, type);
chunk = new PngChunk(length, type);
return true;
}
// A chunk might report a length that exceeds the length of the stream.
// Take the minimum of the two values to ensure we don't read past the end of the stream.
position = this.currentStream.Position;
chunk = new(
chunk = new PngChunk(
length: (int)Math.Min(length, this.currentStream.Length - position),
type: type,
data: this.ReadChunkData(length));

2
src/ImageSharp/Formats/Png/PngDecoderOptions.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Png;
public sealed class PngDecoderOptions : ISpecializedDecoderOptions
{
/// <inheritdoc/>
public DecoderOptions GeneralOptions { get; init; } = new DecoderOptions();
public DecoderOptions GeneralOptions { get; init; } = new();
/// <summary>
/// Gets the maximum memory in bytes that a zTXt, sPLT, iTXt, iCCP, or unknown chunk can occupy when decompressed.

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

@ -265,7 +265,7 @@ internal sealed class PngEncoderCore : IDisposable
{
// Use the previously derived global palette and a shared quantizer to
// quantize the subsequent frames. This allows us to cache the color matching resolution.
paletteQuantizer ??= new(
paletteQuantizer ??= new PaletteQuantizer<TPixel>(
this.configuration,
this.quantizer!.Options,
previousPalette);

2
src/ImageSharp/Formats/Png/PngFormat.cs

@ -15,7 +15,7 @@ public sealed class PngFormat : IImageFormat<PngMetadata, PngFrameMetadata>
/// <summary>
/// Gets the shared instance.
/// </summary>
public static PngFormat Instance { get; } = new PngFormat();
public static PngFormat Instance { get; } = new();
/// <inheritdoc/>
public string Name => "PNG";

6
src/ImageSharp/Formats/Png/PngFrameMetadata.cs

@ -53,7 +53,7 @@ public class PngFrameMetadata : IFormatFrameMetadata<PngFrameMetadata>
/// <param name="frameControl">The chunk to create an instance from.</param>
internal void FromChunk(in FrameControl frameControl)
{
this.FrameDelay = new(frameControl.DelayNumerator, frameControl.DelayDenominator);
this.FrameDelay = new Rational(frameControl.DelayNumerator, frameControl.DelayDenominator);
this.DisposalMode = frameControl.DisposalMode;
this.BlendMode = frameControl.BlendMode;
}
@ -62,7 +62,7 @@ public class PngFrameMetadata : IFormatFrameMetadata<PngFrameMetadata>
public static PngFrameMetadata FromFormatConnectingFrameMetadata(FormatConnectingFrameMetadata metadata)
=> new()
{
FrameDelay = new(metadata.Duration.TotalMilliseconds / 1000),
FrameDelay = new Rational(metadata.Duration.TotalMilliseconds / 1000),
DisposalMode = GetMode(metadata.DisposalMode),
BlendMode = metadata.BlendMode,
};
@ -76,7 +76,7 @@ public class PngFrameMetadata : IFormatFrameMetadata<PngFrameMetadata>
delay = 0;
}
return new()
return new FormatConnectingFrameMetadata
{
ColorTableMode = FrameColorTableMode.Global,
Duration = TimeSpan.FromMilliseconds(delay * 1000),

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

@ -129,7 +129,7 @@ public class PngMetadata : IFormatMetadata<PngMetadata>
4 => PngBitDepth.Bit4,
_ => (bpc <= 8) ? PngBitDepth.Bit8 : PngBitDepth.Bit16,
};
return new()
return new PngMetadata
{
ColorType = color,
BitDepth = bitDepth,
@ -209,7 +209,7 @@ public class PngMetadata : IFormatMetadata<PngMetadata>
break;
}
return new(bpp)
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = alpha,
ColorType = colorType,

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

Loading…
Cancel
Save