Browse Source

Handle nullability in decoder base

pull/1567/head
James Jackson-South 4 years ago
parent
commit
8c580a735c
  1. 15
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs
  2. 7
      src/ImageSharp/Formats/ImageDecoder.cs

15
src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs

@ -22,7 +22,7 @@ internal static class IccProfileConverter
/// <param name="image">The image to convert.</param> /// <param name="image">The image to convert.</param>
/// <param name="inputIccProfile">The input ICC profile.</param> /// <param name="inputIccProfile">The input ICC profile.</param>
/// <param name="outputIccProfile">The output ICC profile. </param> /// <param name="outputIccProfile">The output ICC profile. </param>
public static void Convert(Image image, IccProfile? inputIccProfile, IccProfile? outputIccProfile) public static void Convert(Image image, IccProfile inputIccProfile, IccProfile outputIccProfile)
=> image.AcceptVisitor(new IccProfileConverterVisitor(inputIccProfile, outputIccProfile)); => image.AcceptVisitor(new IccProfileConverterVisitor(inputIccProfile, outputIccProfile));
/// <summary> /// <summary>
@ -32,14 +32,9 @@ internal static class IccProfileConverter
/// <param name="image">The image to convert.</param> /// <param name="image">The image to convert.</param>
/// <param name="inputIccProfile">The input ICC profile.</param> /// <param name="inputIccProfile">The input ICC profile.</param>
/// <param name="outputIccProfile">The output ICC profile. </param> /// <param name="outputIccProfile">The output ICC profile. </param>
public static void Convert<TPixel>(Image<TPixel> image, IccProfile? inputIccProfile, IccProfile? outputIccProfile) public static void Convert<TPixel>(Image<TPixel> image, IccProfile inputIccProfile, IccProfile outputIccProfile)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
if (inputIccProfile is null || outputIccProfile is null)
{
return;
}
IccDataToPcsConverter converterDataToPcs = new(inputIccProfile); IccDataToPcsConverter converterDataToPcs = new(inputIccProfile);
IccPcsToDataConverter converterPcsToData = new(outputIccProfile); IccPcsToDataConverter converterPcsToData = new(outputIccProfile);
Configuration configuration = image.GetConfiguration(); Configuration configuration = image.GetConfiguration();
@ -68,10 +63,10 @@ internal static class IccProfileConverter
private readonly struct IccProfileConverterVisitor : IImageVisitor private readonly struct IccProfileConverterVisitor : IImageVisitor
{ {
private readonly IccProfile? inputIccProfile; private readonly IccProfile inputIccProfile;
private readonly IccProfile? outputIccProfile; private readonly IccProfile outputIccProfile;
public IccProfileConverterVisitor(IccProfile? inputIccProfile, IccProfile? outputIccProfile) public IccProfileConverterVisitor(IccProfile inputIccProfile, IccProfile outputIccProfile)
{ {
this.inputIccProfile = inputIccProfile; this.inputIccProfile = inputIccProfile;
this.outputIccProfile = outputIccProfile; this.outputIccProfile = outputIccProfile;

7
src/ImageSharp/Formats/ImageDecoder.cs

@ -5,6 +5,7 @@
using SixLabors.ImageSharp.ColorSpaces.Conversion.Icc; using SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.Icc; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.Icc;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
@ -157,7 +158,11 @@ public abstract class ImageDecoder : IImageDecoder
return; return;
} }
IccProfileConverter.Convert(image, image.Metadata?.IccProfile, SrgbV4Profile.GetProfile()); IccProfile profile = image.Metadata?.IccProfile;
if (profile is not null)
{
IccProfileConverter.Convert(image, profile, SrgbV4Profile.GetProfile());
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save