Browse Source

Dropped ImageSharpd.Formats

We now default load default formats using reflection only for default configuration, not manual.
af/merge-core
Scott Williams 9 years ago
parent
commit
06b3c4b4e7
  1. 10
      ImageSharp.sln
  2. 32
      src/ImageSharp.Formats/ConfigurationExtensions.cs
  3. 25
      src/ImageSharp.Formats/ImageSharp.Formats.xproj
  4. 6
      src/ImageSharp.Formats/Properties/AssemblyInfo.cs
  5. 76
      src/ImageSharp.Formats/project.json
  6. 9
      src/ImageSharp.Formats/stylecop.json
  7. 52
      src/ImageSharp/Configuration.cs
  8. 14
      tests/ImageSharp.Benchmarks/project.json
  9. 8
      tests/ImageSharp.Tests/ConfigurationTests.cs
  10. 5
      tests/ImageSharp.Tests/TestBase.cs
  11. 15
      tests/ImageSharp.Tests/TestFile.cs
  12. 14
      tests/ImageSharp.Tests/project.json

10
ImageSharp.sln

@ -37,8 +37,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E919DF0B
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "build", "build\build.xproj", "{575A5002-DD9F-4335-AA47-1DD87FA13645}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Formats", "src\ImageSharp.Formats\ImageSharp.Formats.xproj", "{C72B8906-260A-4688-9B7A-5CD4BDF419EC}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Formats.Bmp", "src\ImageSharp.Formats.Bmp\ImageSharp.Formats.Bmp.xproj", "{C77661B9-F793-422E-8E27-AC60ECC5F215}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Formats.Gif", "src\ImageSharp.Formats.Gif\ImageSharp.Formats.Gif.xproj", "{27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F}"
@ -50,6 +48,9 @@ EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Processing", "src\ImageSharp.Processing\ImageSharp.Processing.xproj", "{A623CFE9-9D2B-4528-AD1F-2E834B061134}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{9E574A07-F879-4811-9C41-5CBDC6BAFDB7}"
ProjectSection(SolutionItems) = preProject
src\Shared\AssemblyInfo.Common.cs = src\Shared\AssemblyInfo.Common.cs
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -77,10 +78,6 @@ Global
{575A5002-DD9F-4335-AA47-1DD87FA13645}.Debug|Any CPU.Build.0 = Debug|Any CPU
{575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|Any CPU.ActiveCfg = Release|Any CPU
{575A5002-DD9F-4335-AA47-1DD87FA13645}.Release|Any CPU.Build.0 = Release|Any CPU
{C72B8906-260A-4688-9B7A-5CD4BDF419EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C72B8906-260A-4688-9B7A-5CD4BDF419EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C72B8906-260A-4688-9B7A-5CD4BDF419EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C72B8906-260A-4688-9B7A-5CD4BDF419EC}.Release|Any CPU.Build.0 = Release|Any CPU
{C77661B9-F793-422E-8E27-AC60ECC5F215}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C77661B9-F793-422E-8E27-AC60ECC5F215}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C77661B9-F793-422E-8E27-AC60ECC5F215}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -111,7 +108,6 @@ Global
{299D8E18-102C-42DE-ADBF-79098EE706A8} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{2E33181E-6E28-4662-A801-E2E7DC206029} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{575A5002-DD9F-4335-AA47-1DD87FA13645} = {E919DF0B-2607-4462-8FC0-5C98FE50F8C9}
{C72B8906-260A-4688-9B7A-5CD4BDF419EC} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{C77661B9-F793-422E-8E27-AC60ECC5F215} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{7213767C-0003-41CA-AB18-0223CFA7CE4B} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}

32
src/ImageSharp.Formats/ConfigurationExtensions.cs

@ -1,32 +0,0 @@
// <copyright file="ConfigurationExtensions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.IO;
using Formats;
/// <summary>
/// Extension methods for the <see cref="Configuration"/> type.
/// </summary>
public static partial class ConfigurationExtensions
{
/// <summary>
/// Adds the common formats, PNG, JPEG, GIF and BMP.
/// </summary>
/// <param name="config">The config.</param>
/// <returns>The config</returns>
public static Configuration AddCommonFormats(this Configuration config)
{
return config
.AddPngFormat()
.AddJpegFormat()
.AddGifFormat()
.AddBmpFormat();
}
}
}

25
src/ImageSharp.Formats/ImageSharp.Formats.xproj

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>c72b8906-260a-4688-9b7a-5cd4bdf419ec</ProjectGuid>
<RootNamespace>ImageSharp.Formats</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

6
src/ImageSharp.Formats/Properties/AssemblyInfo.cs

@ -1,6 +0,0 @@
// <copyright file="AssemblyInfo.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// Common values read from `AssemblyInfo.Common.cs`

76
src/ImageSharp.Formats/project.json

@ -1,76 +0,0 @@
{
"version": "1.0.0-alpha1-*",
"title": "ImageSharp.Formats",
"description": "A cross-platform library for the processing of image files; written in C#",
"authors": [
"James Jackson-South and contributors"
],
"packOptions": {
"owners": [
"James Jackson-South and contributors"
],
"projectUrl": "https://github.com/JimBobSquarePants/ImageSharp",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"iconUrl": "https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png",
"requireLicenseAcceptance": false,
"repository": {
"type": "git",
"url": "https://github.com/JimBobSquarePants/ImageSharp"
},
"tags": [
"Image Resize Crop Gif Jpg Jpeg Bitmap Png Core"
]
},
"buildOptions": {
"allowUnsafe": true,
"xmlDoc": true,
"additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ],
"compile": [
"../Shared/*.cs"
]
},
"configurations": {
"Release": {
"buildOptions": {
"warningsAsErrors": true,
"optimize": true
}
}
},
"dependencies": {
"ImageSharp": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Png": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Bmp": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Jpeg": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Gif": {
"target": "project",
"version": "1.0.0-*"
},
"StyleCop.Analyzers": {
"version": "1.1.0-beta001",
"type": "build"
}
},
"frameworks": {
"netstandard1.1": {
"dependencies": {
}
},
"net45": {
"dependencies": {
}
}
}
}

9
src/ImageSharp.Formats/stylecop.json

@ -1,9 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "James Jackson-South",
"copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0."
}
}
}

52
src/ImageSharp/Configuration.cs

@ -21,7 +21,7 @@ namespace ImageSharp
/// <summary>
/// A lazily initialized configuration default instance.
/// </summary>
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => new Configuration());
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => new Configuration(true));
/// <summary>
/// An object that can be used to synchronize access to the <see cref="Configuration"/>.
@ -33,6 +33,30 @@ namespace ImageSharp
/// </summary>
private readonly List<IImageFormat> imageFormatsList = new List<IImageFormat>();
/// <summary>
/// Initializes a new instance of the <see cref="Configuration"/> class.
/// </summary>
public Configuration()
: this(false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Configuration" /> class.
/// </summary>
/// <param name="autoloadWellknownFormats">if set to <c>true</c> [autoload wellknown formats].</param>
internal Configuration(bool autoloadWellknownFormats)
{
if (autoloadWellknownFormats)
{
// lets try auto loading the known image formats
this.TryAddImageFormat("ImageSharp.Formats.PngFormat, ImageSharp.Formats.Png");
this.TryAddImageFormat("ImageSharp.Formats.JpegFormat, ImageSharp.Formats.Jpeg");
this.TryAddImageFormat("ImageSharp.Formats.GifFormat, ImageSharp.Formats.Gif");
this.TryAddImageFormat("ImageSharp.Formats.BmpFormat, ImageSharp.Formats.Bmp");
}
}
/// <summary>
/// Gets the default <see cref="Configuration"/> instance.
/// </summary>
@ -69,6 +93,32 @@ namespace ImageSharp
this.AddImageFormatLocked(format);
}
/// <summary>
/// Tries the add image format.
/// </summary>
/// <param name="typeName">Name of the type.</param>
/// <returns>True if type discoverd and is a valid <see cref="IImageFormat"/></returns>
internal bool TryAddImageFormat(string typeName)
{
Type type = Type.GetType(typeName, false);
if (type != null)
{
IImageFormat format = Activator.CreateInstance(type) as IImageFormat;
if (format != null
&& format.Encoder != null
&& format.Decoder != null
&& !string.IsNullOrEmpty(format.MimeType)
&& format.SupportedExtensions?.Any() == true)
{
// we can use the locked version as we have already validated in the if.
this.AddImageFormatLocked(format);
return true;
}
}
return false;
}
/// <summary>
/// Adds image format. The class is locked to make it thread safe.
/// </summary>

14
tests/ImageSharp.Benchmarks/project.json

@ -23,7 +23,19 @@
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats": {
"ImageSharp.Formats.Jpeg": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Png": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Bmp": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Gif": {
"target": "project",
"version": "1.0.0-*"
},

8
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -18,6 +18,14 @@ namespace ImageSharp.Tests
/// </summary>
public class ConfigurationTests
{
[Fact]
public void IfAutoloadWellknwonFormatesIsTrueAllFormateAreLoaded()
{
var configuration = new Configuration(true);
Assert.Equal(4, configuration.ImageFormats.Count);
}
/// <summary>
/// Test that the default configuration is not null.
/// </summary>

5
tests/ImageSharp.Tests/TestBase.cs

@ -13,11 +13,6 @@ namespace ImageSharp.Tests
/// </summary>
public abstract class TestBase
{
protected TestBase()
{
Configuration.Default.AddCommonFormats();
}
/// <summary>
/// Creates the image output directory.
/// </summary>

15
tests/ImageSharp.Tests/TestFile.cs

@ -35,20 +35,7 @@ namespace ImageSharp.Tests
/// The file.
/// </summary>
private readonly string file;
/// <summary>
/// Initializes static members of the <see cref="TestFile"/> class.
/// </summary>
static TestFile()
{
// Register the individual image formats.
// TODO: Is this the best place to do this?
Configuration.Default.AddImageFormat(new PngFormat());
Configuration.Default.AddImageFormat(new JpegFormat());
Configuration.Default.AddImageFormat(new BmpFormat());
Configuration.Default.AddImageFormat(new GifFormat());
}
/// <summary>
/// Initializes a new instance of the <see cref="TestFile"/> class.
/// </summary>

14
tests/ImageSharp.Tests/project.json

@ -30,7 +30,19 @@
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats": {
"ImageSharp.Formats.Png": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Jpeg": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Bmp": {
"target": "project",
"version": "1.0.0-*"
},
"ImageSharp.Formats.Gif": {
"target": "project",
"version": "1.0.0-*"
},

Loading…
Cancel
Save