Browse Source

Merge remote-tracking branch 'jimbob/master' into progressive-playground

pull/97/head
Anton Firszov 10 years ago
parent
commit
1337d6ebbf
  1. 18
      src/ImageSharp.Drawing/project.json
  2. 18
      src/ImageSharp.Formats.Bmp/project.json
  3. 18
      src/ImageSharp.Formats.Gif/project.json
  4. 19
      src/ImageSharp.Formats.Jpeg/Components/Block8x8F.cs
  5. 12
      src/ImageSharp.Formats.Jpeg/JpegEncoder.cs
  6. 18
      src/ImageSharp.Formats.Jpeg/project.json
  7. 18
      src/ImageSharp.Formats.Png/project.json
  8. 18
      src/ImageSharp.Processing/project.json
  9. 18
      src/ImageSharp/project.json
  10. 2
      tests/ImageSharp.Benchmarks/project.json
  11. 18
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  12. 1
      tests/ImageSharp.Sandbox46/packages.config
  13. 27
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  14. 18
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs
  15. 8
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs

18
src/ImageSharp.Drawing/project.json

@ -51,7 +51,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -63,6 +62,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -76,7 +76,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0" "System.Numerics.Vectors": "4.1.1",
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

18
src/ImageSharp.Formats.Bmp/project.json

@ -47,7 +47,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -59,6 +58,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -72,9 +72,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

18
src/ImageSharp.Formats.Gif/project.json

@ -47,7 +47,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -59,6 +58,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -72,9 +72,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

19
src/ImageSharp.Formats.Jpeg/Components/Block8x8F.cs

@ -377,23 +377,6 @@ namespace ImageSharp.Formats.Jpg
} }
} }
/// <summary>
/// Performs division and rounding of a rational number represented by a dividend and a divisior into an integer.
/// </summary>
/// <param name="dividend">The dividend</param>
/// <param name="divisor">The divisor</param>
/// <returns>The result integer</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int DivideRound(int dividend, int divisor)
{
if (dividend >= 0)
{
return (dividend + (divisor >> 1)) / divisor;
}
return -((-dividend + (divisor >> 1)) / divisor);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b) private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b)
{ {
@ -418,9 +401,11 @@ namespace ImageSharp.Formats.Jpg
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor) private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor)
{ {
// sign(v) = max(min(v, 1), -1)
Vector4 sign = Vector4.Min(dividend, Vector4.One); Vector4 sign = Vector4.Min(dividend, Vector4.One);
sign = Vector4.Max(sign, new Vector4(-1)); sign = Vector4.Max(sign, new Vector4(-1));
// AlmostRound(dividend/divisor) = dividend/divisior + 0.5*sign(dividend)
return (dividend / divisor) + (sign * new Vector4(0.5f)); return (dividend / divisor) + (sign * new Vector4(0.5f));
} }
} }

12
src/ImageSharp.Formats.Jpeg/JpegEncoder.cs

@ -63,7 +63,13 @@ namespace ImageSharp.Formats
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream) public void Encode<TColor>(Image<TColor> image, Stream stream)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
// Ensure that quality can be set but has a fallback.
if (image.Quality > 0)
{
this.Quality = image.Quality;
}
JpegEncoderCore encode = new JpegEncoderCore(); JpegEncoderCore encode = new JpegEncoderCore();
if (this.subsampleSet) if (this.subsampleSet)
{ {
@ -71,8 +77,8 @@ namespace ImageSharp.Formats
} }
else else
{ {
// Match Photoshop and use 4:2:0 SUpsampling at quality < 51% // Use 4:2:0 Subsampling at quality < 91% for reduced filesize.
encode.Encode(image, stream, this.Quality, this.Quality >= 51 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420); encode.Encode(image, stream, this.Quality, this.Quality >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);
} }
} }
} }

18
src/ImageSharp.Formats.Jpeg/project.json

@ -47,7 +47,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -59,6 +58,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -72,9 +72,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

18
src/ImageSharp.Formats.Png/project.json

@ -47,7 +47,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -59,6 +58,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -72,9 +72,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

18
src/ImageSharp.Processing/project.json

@ -47,7 +47,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -59,6 +58,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -72,9 +72,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

18
src/ImageSharp/project.json

@ -43,7 +43,6 @@
"type": "build" "type": "build"
}, },
"System.Buffers": "4.0.0", "System.Buffers": "4.0.0",
"System.Numerics.Vectors": "4.1.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0" "System.Runtime.CompilerServices.Unsafe": "4.0.0"
}, },
"frameworks": { "frameworks": {
@ -55,6 +54,7 @@
"System.IO": "4.1.0", "System.IO": "4.1.0",
"System.IO.Compression": "4.1.0", "System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0", "System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12", "System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1", "System.Resources.ResourceManager": "4.0.1",
"System.Runtime.Extensions": "4.1.0", "System.Runtime.Extensions": "4.1.0",
@ -68,9 +68,21 @@
}, },
"net45": { "net45": {
"dependencies": { "dependencies": {
"System.Runtime": "4.0.0", "System.Numerics.Vectors": "4.1.1",
"System.IO": "4.0.0",
"System.Threading.Tasks.Parallel": "4.0.0" "System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.0.0"
}
},
"net461": {
"dependencies": {
"System.Threading.Tasks.Parallel": "4.0.0"
},
"frameworkAssemblies": {
"System.Runtime": "4.0.20.0",
"System.Numerics": "4.0.0.0",
"System.Numerics.Vectors": "4.0.0.0"
} }
} }
} }

2
tests/ImageSharp.Benchmarks/project.json

@ -48,7 +48,7 @@
"ImageSharp.Benchmarks": "ImageSharp.Benchmarks" "ImageSharp.Benchmarks": "ImageSharp.Benchmarks"
}, },
"frameworks": { "frameworks": {
"net461": { "net46": {
"dependencies": { "dependencies": {
}, },
"frameworkAssemblies": { "frameworkAssemblies": {

18
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -38,10 +38,6 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Numerics" /> <Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Numerics.Vectors.4.1.1\lib\net46\System.Numerics.Vectors.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
@ -67,25 +63,25 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ImageSharp"> <Reference Include="ImageSharp">
<HintPath>..\..\src\ImageSharp\bin\$(Configuration)\net45\ImageSharp.dll</HintPath> <HintPath>..\..\src\ImageSharp\bin\$(Configuration)\net461\ImageSharp.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Drawing"> <Reference Include="ImageSharp.Drawing">
<HintPath>..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net45\ImageSharp.Drawing.dll</HintPath> <HintPath>..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\ImageSharp.Drawing.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Formats.Bmp"> <Reference Include="ImageSharp.Formats.Bmp">
<HintPath>..\..\src\ImageSharp.Formats.Bmp\bin\$(Configuration)\net45\ImageSharp.Formats.Bmp.dll</HintPath> <HintPath>..\..\src\ImageSharp.Formats.Bmp\bin\$(Configuration)\net461\ImageSharp.Formats.Bmp.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Formats.Gif"> <Reference Include="ImageSharp.Formats.Gif">
<HintPath>..\..\src\ImageSharp.Formats.Gif\bin\$(Configuration)\net45\ImageSharp.Formats.Gif.dll</HintPath> <HintPath>..\..\src\ImageSharp.Formats.Gif\bin\$(Configuration)\net461\ImageSharp.Formats.Gif.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Formats.Jpeg"> <Reference Include="ImageSharp.Formats.Jpeg">
<HintPath>..\..\src\ImageSharp.Formats.Jpeg\bin\$(Configuration)\net45\ImageSharp.Formats.Jpeg.dll</HintPath> <HintPath>..\..\src\ImageSharp.Formats.Jpeg\bin\$(Configuration)\net461\ImageSharp.Formats.Jpeg.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Formats.Png"> <Reference Include="ImageSharp.Formats.Png">
<HintPath>..\..\src\ImageSharp.Formats.Png\bin\$(Configuration)\net45\ImageSharp.Formats.Png.dll</HintPath> <HintPath>..\..\src\ImageSharp.Formats.Png\bin\$(Configuration)\net461\ImageSharp.Formats.Png.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Processing"> <Reference Include="ImageSharp.Processing">
<HintPath>..\..\src\ImageSharp.Processing\bin\$(Configuration)\net45\ImageSharp.Processing.dll</HintPath> <HintPath>..\..\src\ImageSharp.Processing\bin\$(Configuration)\net461\ImageSharp.Processing.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

1
tests/ImageSharp.Sandbox46/packages.config

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="System.Numerics.Vectors" version="4.1.1" targetFramework="net461" />
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="net461" /> <package id="xunit" version="2.2.0-beta4-build3444" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" /> <package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.assert" version="2.2.0-beta4-build3444" targetFramework="net461" /> <package id="xunit.assert" version="2.2.0-beta4-build3444" targetFramework="net461" />

27
tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs

@ -34,7 +34,7 @@ namespace ImageSharp.Tests
public void LoadResizeSave<TColor>(TestImageProvider<TColor> provider, int quality, JpegSubsample subsample) public void LoadResizeSave<TColor>(TestImageProvider<TColor> provider, int quality, JpegSubsample subsample)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = provider.GetImage() Image<TColor> image = provider.GetImage()
.Resize(new ResizeOptions .Resize(new ResizeOptions
{ {
Size = new Size(150, 100), Size = new Size(150, 100),
@ -61,7 +61,7 @@ namespace ImageSharp.Tests
.Concat(new[] { TestImages.Jpeg.Calliphora, TestImages.Jpeg.Cmyk }) .Concat(new[] { TestImages.Jpeg.Calliphora, TestImages.Jpeg.Cmyk })
.ToArray(); .ToArray();
var testImages = Image<Color>[] testImages =
testFiles.Select( testFiles.Select(
tf => TestImageProvider<Color>.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) tf => TestImageProvider<Color>.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage())
.ToArray(); .ToArray();
@ -91,7 +91,7 @@ namespace ImageSharp.Tests
public void OpenJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider) public void OpenJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = provider.GetImage(); Image<TColor> image = provider.GetImage();
provider.Utility.SaveTestOutputFile(image, "bmp"); provider.Utility.SaveTestOutputFile(image, "bmp");
} }
@ -105,9 +105,9 @@ namespace ImageSharp.Tests
public void OpenBmp_SaveJpeg<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality) public void OpenBmp_SaveJpeg<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = provider.GetImage(); Image<TColor> image = provider.GetImage();
var utility = provider.Utility; ImagingTestCaseUtility utility = provider.Utility;
utility.TestName += "_" + subSample + "_Q" + quality; utility.TestName += "_" + subSample + "_Q" + quality;
using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg"))) using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg")))
@ -152,6 +152,7 @@ namespace ImageSharp.Tests
{ {
Image img = new Image(bytes); Image img = new Image(bytes);
}, },
// ReSharper disable once ExplicitCallerInfoArgument
$"Decode {fileName}"); $"Decode {fileName}");
} }
@ -162,11 +163,11 @@ namespace ImageSharp.Tests
public void Benchmark_JpegEncoder<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality) public void Benchmark_JpegEncoder<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = provider.GetImage(); Image<TColor> image = provider.GetImage();
using (var outputStream = new MemoryStream()) using (var outputStream = new MemoryStream())
{ {
var encoder = new JpegEncoder() JpegEncoder encoder = new JpegEncoder()
{ {
Subsample = subSample, Subsample = subSample,
Quality = quality Quality = quality
@ -185,7 +186,7 @@ namespace ImageSharp.Tests
{ {
Image<TColor> image = factory.CreateImage(10, 10); Image<TColor> image = factory.CreateImage(10, 10);
using (var pixels = image.Lock()) using (PixelAccessor<TColor> pixels = image.Lock())
{ {
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -208,10 +209,10 @@ namespace ImageSharp.Tests
public void CopyStretchedRGBTo_FromOrigo<TColor>(TestImageProvider<TColor> provider) public void CopyStretchedRGBTo_FromOrigo<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var src = provider.GetImage(); Image<TColor> src = provider.GetImage();
PixelArea<TColor> area = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz); PixelArea<TColor> area = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz);
var dest = provider.Factory.CreateImage(8, 8); Image<TColor> dest = provider.Factory.CreateImage(8, 8);
using (var s = src.Lock()) using (var s = src.Lock())
{ {
@ -233,12 +234,12 @@ namespace ImageSharp.Tests
public void CopyStretchedRGBTo_WithOffset<TColor>(TestImageProvider<TColor> provider) public void CopyStretchedRGBTo_WithOffset<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var src = provider.GetImage(); Image<TColor> src = provider.GetImage();
PixelArea<TColor> area = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz); PixelArea<TColor> area = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz);
var dest = provider.Factory.CreateImage(8, 8); Image<TColor> dest = provider.Factory.CreateImage(8, 8);
using (var s = src.Lock()) using (PixelAccessor<TColor> s = src.Lock())
{ {
using (var d = dest.Lock()) using (var d = dest.Lock())
{ {

18
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs

@ -21,7 +21,7 @@ namespace ImageSharp.Tests
internal static class ReferenceImplementations internal static class ReferenceImplementations
{ {
/// <summary> /// <summary>
/// Transpose 8x8 block stored linearly in a span (inplace) /// Transpose 8x8 block stored linearly in a <see cref="MutableSpan{T}"/> (inplace)
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
internal static void Transpose8x8(MutableSpan<float> data) internal static void Transpose8x8(MutableSpan<float> data)
@ -39,7 +39,7 @@ namespace ImageSharp.Tests
} }
/// <summary> /// <summary>
/// Transpose 8x8 block stored linearly in a span /// Transpose 8x8 block stored linearly in a <see cref="MutableSpan{T}"/>
/// </summary> /// </summary>
internal static void Transpose8x8(MutableSpan<float> src, MutableSpan<float> dest) internal static void Transpose8x8(MutableSpan<float> src, MutableSpan<float> dest)
{ {
@ -876,6 +876,14 @@ namespace ImageSharp.Tests
} }
} }
/// <summary>
/// Reference implementation to test <see cref="Block8x8F.UnzigDivRound"/>.
/// Rounding is done used an integer-based algorithm defined in <see cref="RationalRound"/>.
/// </summary>
/// <param name="src">The input block</param>
/// <param name="dest">The destination block of integers</param>
/// <param name="qt">The quantization table</param>
/// <param name="unzigPtr">Pointer to <see cref="UnzigData.Data"/> </param>
public static unsafe void UnZigDivRoundRational(Block8x8F* src, int* dest, Block8x8F* qt, int* unzigPtr) public static unsafe void UnZigDivRoundRational(Block8x8F* src, int* dest, Block8x8F* qt, int* unzigPtr)
{ {
float* s = (float*)src; float* s = (float*)src;
@ -891,6 +899,12 @@ namespace ImageSharp.Tests
} }
} }
/// <summary>
/// Rounds a rational number defined as dividend/divisor into an integer
/// </summary>
/// <param name="dividend">The dividend</param>
/// <param name="divisor">The divisior</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int RationalRound(int dividend, int divisor) private static int RationalRound(int dividend, int divisor)
{ {

8
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.cs

@ -97,13 +97,7 @@ namespace ImageSharp.Tests.Formats.Jpg
Assert.Equal(expected, actual, new ApproximateFloatComparer(2f)); Assert.Equal(expected, actual, new ApproximateFloatComparer(2f));
} }
} }
[Fact]
public void HowMuchIsTheFish()
{
Output.WriteLine(Vector<int>.Count.ToString());
}
[Theory] [Theory]
[InlineData(42)] [InlineData(42)]
[InlineData(1)] [InlineData(1)]

Loading…
Cancel
Save