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;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -18,17 +17,12 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Provides initialization code which allows extending the library. /// Provides initialization code which allows extending the library.
/// </summary> /// </summary>
public sealed partial class Configuration public sealed class Configuration
{ {
/// <summary> /// <summary>
/// A lazily initialized configuration default instance. /// A lazily initialized configuration default instance.
/// </summary> /// </summary>
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => CreateDefaultInstance()); 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();
/// <summary> /// <summary>
/// The list of supported <see cref="IImageEncoder"/> keyed to mime types. /// 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the bmp format. /// Registers the image encoders, decoders and mime type detectors for the bmp format.
/// </summary> /// </summary>
@ -24,4 +18,4 @@ namespace ImageSharp.Formats
config.AddImageFormatDetector(new BmpImageFormatDetector()); config.AddImageFormatDetector(new BmpImageFormatDetector());
} }
} }
} }

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format. /// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/> /// <inheritdoc/>
public IEnumerable<string> FileExtensions => BmpConstants.FileExtensions; 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Detects bmp file headers /// Detects bmp file headers
@ -32,9 +28,10 @@ namespace ImageSharp.Formats
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{ {
// TODO: This should be in constants
return header.Length >= this.HeaderSize && return header.Length >= this.HeaderSize &&
header[0] == 0x42 && // B header[0] == 0x42 && // B
header[1] == 0x4D; // M 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the gif format. /// Registers the image encoders, decoders and mime type detectors for the gif format.
/// </summary> /// </summary>
@ -25,4 +19,4 @@ namespace ImageSharp.Formats
config.AddImageFormatDetector(new GifImageFormatDetector()); config.AddImageFormatDetector(new GifImageFormatDetector());
} }
} }
} }

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

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

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format. /// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/> /// <inheritdoc/>
public IEnumerable<string> FileExtensions => GifConstants.FileExtensions; 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Detects gif file headers /// Detects gif file headers
@ -32,6 +28,7 @@ namespace ImageSharp.Formats
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
{ {
// TODO: This should be in constants
return header.Length >= this.HeaderSize && return header.Length >= this.HeaderSize &&
header[0] == 0x47 && // G header[0] == 0x47 && // G
header[1] == 0x49 && // I header[1] == 0x49 && // I
@ -41,4 +38,4 @@ namespace ImageSharp.Formats
header[5] == 0x61; // a header[5] == 0x61; // a
} }
} }
} }

6
src/ImageSharp/Formats/IImageFormat.cs

@ -5,11 +5,7 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Describes an image format. /// Describes an image format.
@ -36,4 +32,4 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
IEnumerable<string> FileExtensions { get; } 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format. /// Registers the image encoders, decoders and mime type detectors for the jpeg format.
/// </summary> /// </summary>

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

@ -5,11 +5,7 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the jpeg format. /// Registers the image encoders, decoders and mime type detectors for the jpeg format.
@ -28,4 +24,4 @@ namespace ImageSharp.Formats
/// <inheritdoc/> /// <inheritdoc/>
public IEnumerable<string> FileExtensions => JpegConstants.FileExtensions; 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. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,10 +6,6 @@
namespace ImageSharp.Formats namespace ImageSharp.Formats
{ {
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Detects Jpeg file headers /// Detects Jpeg file headers
@ -43,6 +39,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJfif(ReadOnlySpan<byte> header) private bool IsJfif(ReadOnlySpan<byte> header)
{ {
// TODO: This should be in constants
bool isJfif = bool isJfif =
header[6] == 0x4A && // J header[6] == 0x4A && // J
header[7] == 0x46 && // F header[7] == 0x46 && // F
@ -60,6 +57,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsExif(ReadOnlySpan<byte> header) private bool IsExif(ReadOnlySpan<byte> header)
{ {
// TODO: This should be in constants
bool isExif = bool isExif =
header[6] == 0x45 && // E header[6] == 0x45 && // E
header[7] == 0x78 && // X header[7] == 0x78 && // X
@ -78,6 +76,7 @@ namespace ImageSharp.Formats
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJpeg(ReadOnlySpan<byte> header) private bool IsJpeg(ReadOnlySpan<byte> header)
{ {
// TODO: This should be in constants
bool isJpg = bool isJpg =
header[0] == 0xFF && // 255 header[0] == 0xFF && // 255
header[1] == 0xD8; // 216 header[1] == 0xD8; // 216
@ -85,4 +84,4 @@ namespace ImageSharp.Formats
return isJpg; return isJpg;
} }
} }
} }

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

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

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

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

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

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

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

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

4
src/ImageSharp/IConfigurationModule.cs

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

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

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

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

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

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

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

6
src/ImageSharp/ImageFormats.cs

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