Browse Source

Use ternary operator

pull/627/head
Jason Nelson 8 years ago
parent
commit
18054f0eb7
  1. 7
      src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
  2. 23
      src/ImageSharp/Formats/ImageFormatManager.cs
  3. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
  4. 7
      src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
  5. 8
      src/ImageSharp/Image.Decode.cs

7
src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs

@ -16,12 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
{
if (this.IsSupportedFileFormat(header))
{
return ImageFormats.Bmp;
}
return null;
return this.IsSupportedFileFormat(header) ? ImageFormats.Bmp : null;
}
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)

23
src/ImageSharp/Formats/ImageFormatManager.cs

@ -5,7 +5,6 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SixLabors.ImageSharp.Formats
{
@ -87,9 +86,9 @@ namespace SixLabors.ImageSharp.Formats
{
Guard.NotNullOrWhiteSpace(extension, nameof(extension));
if (extension[0] == '.')
{
extension = extension.Substring(1);
if (extension[0] == '.')
{
extension = extension.Substring(1);
}
return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
@ -158,12 +157,10 @@ namespace SixLabors.ImageSharp.Formats
public IImageDecoder FindDecoder(IImageFormat format)
{
Guard.NotNull(format, nameof(format));
if (this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder decoder))
{
return decoder;
}
return null;
return this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder decoder)
? decoder
: null;
}
/// <summary>
@ -174,12 +171,10 @@ namespace SixLabors.ImageSharp.Formats
public IImageEncoder FindEncoder(IImageFormat format)
{
Guard.NotNull(format, nameof(format));
if (this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder encoder))
{
return encoder;
}
return null;
return this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder encoder)
? encoder
: null;
}
/// <summary>

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

@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
/// Returns the <see cref="JpegColorConverter"/> for the YCbCr colorspace that matches the current CPU architecture.
/// </summary>
private static JpegColorConverter GetYCbCrConverter() =>
JpegColorConverter.FromYCbCrSimdAvx2.IsAvailable ? (JpegColorConverter)new JpegColorConverter.FromYCbCrSimdAvx2() : new JpegColorConverter.FromYCbCrSimd();
FromYCbCrSimdAvx2.IsAvailable ? (JpegColorConverter)new FromYCbCrSimdAvx2() : new FromYCbCrSimd();
/// <summary>
/// A stack-only struct to reference the input buffers using <see cref="ReadOnlySpan{T}"/>-s.

7
src/ImageSharp/Formats/Png/PngImageFormatDetector.cs

@ -17,12 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
{
if (this.IsSupportedFileFormat(header))
{
return ImageFormats.Png;
}
return null;
return this.IsSupportedFileFormat(header) ? ImageFormats.Png : null;
}
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)

8
src/ImageSharp/Image.Decode.cs

@ -48,12 +48,10 @@ namespace SixLabors.ImageSharp
private static IImageDecoder DiscoverDecoder(Stream stream, Configuration config, out IImageFormat format)
{
format = InternalDetectFormat(stream, config);
if (format != null)
{
return config.ImageFormatsManager.FindDecoder(format);
}
return null;
return format != null
? config.ImageFormatsManager.FindDecoder(format)
: null;
}
#pragma warning disable SA1008 // Opening parenthesis must be spaced correctly

Loading…
Cancel
Save