Browse Source

Minor cleanup

pull/254/head
James Jackson-South 9 years ago
parent
commit
fe346134fe
  1. 10
      src/ImageSharp/Configuration.cs
  2. 10
      src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs
  3. 6
      src/ImageSharp/Formats/Bmp/BmpFormat.cs
  4. 9
      src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs
  5. 10
      src/ImageSharp/Formats/Gif/GifConfigurationModule.cs
  6. 2
      src/ImageSharp/Formats/Gif/GifConstants.cs
  7. 6
      src/ImageSharp/Formats/Gif/GifFormat.cs
  8. 9
      src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs
  9. 6
      src/ImageSharp/Formats/IImageFormat.cs
  10. 8
      src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
  11. 6
      src/ImageSharp/Formats/Jpeg/JpegFormat.cs
  12. 11
      src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
  13. 8
      src/ImageSharp/Formats/Png/PngConfigurationModule.cs
  14. 3
      src/ImageSharp/Formats/Png/PngConstants.cs
  15. 6
      src/ImageSharp/Formats/Png/PngFormat.cs
  16. 7
      src/ImageSharp/Formats/Png/PngImageFormatDetector.cs
  17. 4
      src/ImageSharp/IConfigurationModule.cs
  18. 1
      src/ImageSharp/Image/Image.Decode.cs
  19. 2
      src/ImageSharp/Image/Image.FromStream.cs
  20. 1
      src/ImageSharp/Image/Image{TPixel}.cs
  21. 6
      src/ImageSharp/ImageFormats.cs

10
src/ImageSharp/Configuration.cs

@ -8,7 +8,6 @@ namespace ImageSharp
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
@ -18,17 +17,12 @@ namespace ImageSharp
/// <summary>
/// Provides initialization code which allows extending the library.
/// </summary>
public sealed partial class Configuration
public sealed class Configuration
{
/// <summary>
/// A lazily initialized configuration default instance.
/// </summary>
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => CreateDefaultInstance());
/// <summary>
/// An object that can be used to synchronize access to the <see cref="Configuration"/>.
/// </summary>
private readonly object syncRoot = new object();
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(CreateDefaultInstance);
/// <summary>
/// The list of supported <see cref="IImageEncoder"/> keyed to mime types.

10
src/ImageSharp/Formats/Bmp/BmpConfigurationModule.cs

@ -1,16 +1,10 @@
// <copyright file="ConfigurationModule.cs" company="James Jackson-South">
// <copyright file="BmpConfigurationModule.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the bmp format.
/// </summary>
@ -24,4 +18,4 @@ namespace ImageSharp.Formats
config.AddImageFormatDetector(new BmpImageFormatDetector());
}
}
}
}

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/>
public IEnumerable<string> FileExtensions => BmpConstants.FileExtensions;
}
}
}

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

@ -1,4 +1,4 @@
// <copyright file="PngMimeTypeDetector.cs" company="James Jackson-South">
// <copyright file="BmpImageFormatDetector.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Detects bmp file headers
@ -32,9 +28,10 @@ namespace ImageSharp.Formats
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
return header.Length >= this.HeaderSize &&
header[0] == 0x42 && // B
header[1] == 0x4D; // M
}
}
}
}

10
src/ImageSharp/Formats/Gif/GifConfigurationModule.cs

@ -1,16 +1,10 @@
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
// <copyright file="GifConfigurationModule.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the gif format.
/// </summary>
@ -25,4 +19,4 @@ namespace ImageSharp.Formats
config.AddImageFormatDetector(new GifImageFormatDetector());
}
}
}
}

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

@ -103,4 +103,4 @@ namespace ImageSharp.Formats
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "gif" };
}
}
}

6
src/ImageSharp/Formats/Gif/GifFormat.cs

@ -5,11 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/>
public IEnumerable<string> FileExtensions => GifConstants.FileExtensions;
}
}
}

9
src/ImageSharp/Formats/Gif/GifImageFormatDetector.cs

@ -1,4 +1,4 @@
// <copyright file="PngMimeTypeDetector.cs" company="James Jackson-South">
// <copyright file="GifImageFormatDetector.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Detects gif file headers
@ -32,6 +28,7 @@ namespace ImageSharp.Formats
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
return header.Length >= this.HeaderSize &&
header[0] == 0x47 && // G
header[1] == 0x49 && // I
@ -41,4 +38,4 @@ namespace ImageSharp.Formats
header[5] == 0x61; // a
}
}
}
}

6
src/ImageSharp/Formats/IImageFormat.cs

@ -5,11 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Describes an image format.
@ -36,4 +32,4 @@ namespace ImageSharp.Formats
/// </summary>
IEnumerable<string> FileExtensions { get; }
}
}
}

8
src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs

@ -1,16 +1,10 @@
// <copyright file="PngImageFormatProvider.cs" company="James Jackson-South">
// <copyright file="JpegConfigurationModule.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
/// </summary>

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/>
public IEnumerable<string> FileExtensions => JpegConstants.FileExtensions;
}
}
}

11
src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs

@ -1,4 +1,4 @@
// <copyright file="PngMimeTypeDetector.cs" company="James Jackson-South">
// <copyright file="JpegImageFormatDetector.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Detects Jpeg file headers
@ -43,6 +39,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns>
private bool IsJfif(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
bool isJfif =
header[6] == 0x4A && // J
header[7] == 0x46 && // F
@ -60,6 +57,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns>
private bool IsExif(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
bool isExif =
header[6] == 0x45 && // E
header[7] == 0x78 && // X
@ -78,6 +76,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns>
private bool IsJpeg(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
bool isJpg =
header[0] == 0xFF && // 255
header[1] == 0xD8; // 216
@ -85,4 +84,4 @@ namespace ImageSharp.Formats
return isJpg;
}
}
}
}

8
src/ImageSharp/Formats/Png/PngConfigurationModule.cs

@ -5,12 +5,6 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the png format.
/// </summary>
@ -24,4 +18,4 @@ namespace ImageSharp.Formats
host.AddImageFormatDetector(new PngImageFormatDetector());
}
}
}
}

3
src/ImageSharp/Formats/Png/PngConstants.cs

@ -2,6 +2,7 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System.Collections.Generic;
@ -27,4 +28,4 @@ namespace ImageSharp.Formats
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "png" };
}
}
}

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/>
public IEnumerable<string> FileExtensions => PngConstants.FileExtensions;
}
}
}

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

@ -6,10 +6,6 @@
namespace ImageSharp.Formats
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Detects png file headers
@ -32,6 +28,7 @@ namespace ImageSharp.Formats
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{
// TODO: This should be in constants
return header.Length >= this.HeaderSize &&
header[0] == 0x89 &&
header[1] == 0x50 && // P
@ -43,4 +40,4 @@ namespace ImageSharp.Formats
header[7] == 0x0A; // LF
}
}
}
}

4
src/ImageSharp/IConfigurationModule.cs

@ -5,10 +5,6 @@
namespace ImageSharp
{
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// Represents an interface that can register image encoders, decoders and image format detectors.
/// </summary>

1
src/ImageSharp/Image/Image.Decode.cs

@ -5,7 +5,6 @@
namespace ImageSharp
{
using System.Buffers;
using System.IO;
using System.Linq;
using Formats;

2
src/ImageSharp/Image/Image.FromStream.cs

@ -8,7 +8,6 @@ namespace ImageSharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Formats;
@ -190,7 +189,6 @@ namespace ImageSharp
where TPixel : struct, IPixel<TPixel>
{
config = config ?? Configuration.Default;
format = null;
(Image<TPixel> img, IImageFormat format) data = WithSeekableStream(stream, s => Decode<TPixel>(s, config));
format = data.format;

1
src/ImageSharp/Image/Image{TPixel}.cs

@ -9,7 +9,6 @@ namespace ImageSharp
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

6
src/ImageSharp/ImageFormats.cs

@ -5,11 +5,7 @@
namespace ImageSharp
{
using System;
using System.Collections.Generic;
using System.IO;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// The static collection of all the default image formats
@ -36,4 +32,4 @@ namespace ImageSharp
/// </summary>
public static readonly IImageFormat Bitmap = new BmpFormat();
}
}
}
Loading…
Cancel
Save