Browse Source

merge in beta-1

af/merge-core
Scott Williams 9 years ago
parent
commit
30528fd5b3
  1. 8
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  2. 2
      src/ImageSharp/PixelFormats/HalfSingle.cs
  3. 10
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  4. 4
      src/ImageSharp/PixelFormats/Rgba32.cs
  5. 25
      src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
  6. 5
      src/ImageSharp/Processing/Transforms/AutoOrient.cs
  7. 46
      tests/ImageSharp.Tests/ConfigurationTests.cs
  8. 32
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
  9. 8
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  10. 5
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

8
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -128,10 +128,10 @@ namespace SixLabors.ImageSharp
/// </returns>
public static Rectangle GetBoundingRectangle(Rectangle rectangle, Matrix3x2 matrix)
{
Vector2 leftTop = Vector2.Transform(new Vector2(rectangle.Left, rectangle.Top), matrix);
Vector2 rightTop = Vector2.Transform(new Vector2(rectangle.Right, rectangle.Top), matrix);
Vector2 leftBottom = Vector2.Transform(new Vector2(rectangle.Left, rectangle.Bottom), matrix);
Vector2 rightBottom = Vector2.Transform(new Vector2(rectangle.Right, rectangle.Bottom), matrix);
var leftTop = Vector2.Transform(new Vector2(rectangle.Left, rectangle.Top), matrix);
var rightTop = Vector2.Transform(new Vector2(rectangle.Right, rectangle.Top), matrix);
var leftBottom = Vector2.Transform(new Vector2(rectangle.Left, rectangle.Bottom), matrix);
var rightBottom = Vector2.Transform(new Vector2(rectangle.Right, rectangle.Bottom), matrix);
Vector2[] allCorners = { leftTop, rightTop, leftBottom, rightBottom };
float extentX = allCorners.Select(v => v.X).Max() - allCorners.Select(v => v.X).Min();

2
src/ImageSharp/PixelFormats/HalfSingle.cs

@ -178,7 +178,7 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Vector4 ToScaledVector4()
{
Vector4 vector = this.ToVector4();
var vector = this.ToVector4();
vector *= MaxBytes;
vector += Half;
vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);

10
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -50,10 +50,10 @@ namespace SixLabors.ImageSharp
nameof(count),
"Argument 'count' should divisible by Vector<uint>.Count!");
Vector<float> bVec = new Vector<float>(256.0f / 255.0f);
Vector<float> magicFloat = new Vector<float>(32768.0f);
Vector<uint> magicInt = new Vector<uint>(1191182336); // reinterpreded value of 32768.0f
Vector<uint> mask = new Vector<uint>(255);
var bVec = new Vector<float>(256.0f / 255.0f);
var magicFloat = new Vector<float>(32768.0f);
var magicInt = new Vector<uint>(1191182336); // reinterpreded value of 32768.0f
var mask = new Vector<uint>(255);
int unpackedRawCount = count * 4;
@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp
vi &= mask;
vi |= magicInt;
Vector<float> vf = Vector.AsVectorSingle(vi);
var vf = Vector.AsVectorSingle(vi);
vf = (vf - magicFloat) * bVec;
Unsafe.Add(ref destBaseAsFloat, i) = vf;

4
src/ImageSharp/PixelFormats/Rgba32.cs

@ -429,7 +429,7 @@ namespace SixLabors.ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Pack(float x, float y, float z, float w)
{
Vector4 value = new Vector4(x, y, z, w);
var value = new Vector4(x, y, z, w);
this.Pack(ref value);
}
@ -440,7 +440,7 @@ namespace SixLabors.ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Pack(ref Vector3 vector)
{
Vector4 value = new Vector4(vector, 1);
var value = new Vector4(vector, 1);
this.Pack(ref value);
}

25
src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -16,7 +15,13 @@ namespace SixLabors.ImageSharp.Processing.Processors
internal class AutoOrientProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
/// <summary>
/// Initializes a new instance of the <see cref="AutoOrientProcessor{TPixel}"/> class.
/// </summary>
public AutoOrientProcessor()
{
}
protected override void BeforeImageApply(Image<TPixel> source, Rectangle sourceRectangle)
{
Orientation orientation = GetExifOrientation(source);
@ -28,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
break;
case Orientation.BottomRight:
new RotateProcessor<TPixel> { Angle = (int)RotateType.Rotate180, Expand = false }.Apply(source, sourceRectangle);
new RotateProcessor<TPixel>() { Angle = (int)RotateType.Rotate180, Expand = false }.Apply(source, sourceRectangle);
break;
case Orientation.BottomLeft:
@ -36,21 +41,21 @@ namespace SixLabors.ImageSharp.Processing.Processors
break;
case Orientation.LeftTop:
new RotateProcessor<TPixel> { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle);
new RotateProcessor<TPixel>() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle);
new FlipProcessor<TPixel>(FlipType.Horizontal).Apply(source, sourceRectangle);
break;
case Orientation.RightTop:
new RotateProcessor<TPixel> { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle);
new RotateProcessor<TPixel>() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle);
break;
case Orientation.RightBottom:
new FlipProcessor<TPixel>(FlipType.Vertical).Apply(source, sourceRectangle);
new RotateProcessor<TPixel> { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle);
new RotateProcessor<TPixel>() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle);
break;
case Orientation.LeftBottom:
new RotateProcessor<TPixel> { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle);
new RotateProcessor<TPixel>() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle);
break;
case Orientation.Unknown:
@ -60,10 +65,10 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
}
/// <inheritdoc />
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
/// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> sourceBase, Rectangle sourceRectangle, Configuration config)
{
// Nothing required here
// all processing happens at the image level within BeforeImageApply();
}
/// <summary>

5
src/ImageSharp/Processing/Transforms/AutoOrient.cs

@ -1,9 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp
{
@ -20,6 +19,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static IImageProcessingContext<TPixel> AutoOrient<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new Processing.Processors.AutoOrientProcessor<TPixel>());
=> source.ApplyProcessor(new AutoOrientProcessor<TPixel>());
}
}

46
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -30,15 +30,15 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void DefaultsToLocalFileSystem()
{
Assert.IsType<LocalFileSystem>(DefaultConfiguration.FileSystem);
Assert.IsType<LocalFileSystem>(ConfigurationEmpty.FileSystem);
Assert.IsType<LocalFileSystem>(this.DefaultConfiguration.FileSystem);
Assert.IsType<LocalFileSystem>(this.ConfigurationEmpty.FileSystem);
}
[Fact]
public void IfAutoloadWellknwonFormatesIsTrueAllFormateAreLoaded()
{
Assert.Equal(4, DefaultConfiguration.ImageEncoders.Count());
Assert.Equal(4, DefaultConfiguration.ImageDecoders.Count());
Assert.Equal(4, this.DefaultConfiguration.ImageEncoders.Count());
Assert.Equal(4, this.DefaultConfiguration.ImageDecoders.Count());
}
/// <summary>
@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests
{
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.AddImageFormatDetector(null);
this.DefaultConfiguration.AddImageFormatDetector(null);
});
}
@ -83,15 +83,15 @@ namespace SixLabors.ImageSharp.Tests
{
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetEncoder(null, new Mock<IImageEncoder>().Object);
this.DefaultConfiguration.SetEncoder(null, new Mock<IImageEncoder>().Object);
});
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetEncoder(ImageFormats.Bmp, null);
this.DefaultConfiguration.SetEncoder(ImageFormats.Bmp, null);
});
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetEncoder(null, null);
this.DefaultConfiguration.SetEncoder(null, null);
});
}
@ -100,29 +100,29 @@ namespace SixLabors.ImageSharp.Tests
{
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetDecoder(null, new Mock<IImageDecoder>().Object);
this.DefaultConfiguration.SetDecoder(null, new Mock<IImageDecoder>().Object);
});
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetDecoder(ImageFormats.Bmp, null);
this.DefaultConfiguration.SetDecoder(ImageFormats.Bmp, null);
});
Assert.Throws<ArgumentNullException>(() =>
{
DefaultConfiguration.SetDecoder(null, null);
this.DefaultConfiguration.SetDecoder(null, null);
});
}
[Fact]
public void RegisterMimeTypeEncoderReplacesLast()
{
var encoder1 = new Mock<IImageEncoder>().Object;
ConfigurationEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder1);
var found = ConfigurationEmpty.FindEncoder(TestFormat.GlobalTestFormat);
IImageEncoder encoder1 = new Mock<IImageEncoder>().Object;
this.ConfigurationEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder1);
IImageEncoder found = this.ConfigurationEmpty.FindEncoder(TestFormat.GlobalTestFormat);
Assert.Equal(encoder1, found);
var encoder2 = new Mock<IImageEncoder>().Object;
ConfigurationEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder2);
var found2 = ConfigurationEmpty.FindEncoder(TestFormat.GlobalTestFormat);
IImageEncoder encoder2 = new Mock<IImageEncoder>().Object;
this.ConfigurationEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder2);
IImageEncoder found2 = this.ConfigurationEmpty.FindEncoder(TestFormat.GlobalTestFormat);
Assert.Equal(encoder2, found2);
Assert.NotEqual(found, found2);
}
@ -130,14 +130,14 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void RegisterMimeTypeDecoderReplacesLast()
{
var decoder1 = new Mock<IImageDecoder>().Object;
ConfigurationEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder1);
var found = ConfigurationEmpty.FindDecoder(TestFormat.GlobalTestFormat);
IImageDecoder decoder1 = new Mock<IImageDecoder>().Object;
this.ConfigurationEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder1);
IImageDecoder found = this.ConfigurationEmpty.FindDecoder(TestFormat.GlobalTestFormat);
Assert.Equal(decoder1, found);
var decoder2 = new Mock<IImageDecoder>().Object;
ConfigurationEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder2);
var found2 = ConfigurationEmpty.FindDecoder(TestFormat.GlobalTestFormat);
IImageDecoder decoder2 = new Mock<IImageDecoder>().Object;
this.ConfigurationEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder2);
IImageDecoder found2 = this.ConfigurationEmpty.FindDecoder(TestFormat.GlobalTestFormat);
Assert.Equal(decoder2, found2);
Assert.NotEqual(found, found2);
}

32
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Times,
() =>
{
Block8x8F block = new Block8x8F();
var block = new Block8x8F();
for (int i = 0; i < Block8x8F.Size; i++)
{
@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Times,
() =>
{
Block8x8F block = new Block8x8F();
var block = new Block8x8F();
for (int i = 0; i < Block8x8F.Size; i++)
{
@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Times,
() =>
{
Block8x8F b = new Block8x8F();
var b = new Block8x8F();
b.LoadFrom(data);
b.CopyTo(mirror);
});
@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Times,
() =>
{
Block8x8F b = new Block8x8F();
var b = new Block8x8F();
Block8x8F.LoadFrom(&b, data);
Block8x8F.CopyTo(&b, mirror);
});
@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Times,
() =>
{
Block8x8F v = new Block8x8F();
var v = new Block8x8F();
v.LoadFrom(data);
v.CopyTo(mirror);
});
@ -186,10 +186,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
float[] expected = Create8x8FloatData();
ReferenceImplementations.Transpose8x8(expected);
Block8x8F source = new Block8x8F();
var source = new Block8x8F();
source.LoadFrom(Create8x8FloatData());
Block8x8F dest = new Block8x8F();
var dest = new Block8x8F();
source.TransposeInto(ref dest);
float[] actual = new float[64];
@ -206,12 +206,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Fact]
public void TranposeInto_Benchmark()
{
BufferHolder source = new BufferHolder();
var source = new BufferHolder();
source.Buffer.LoadFrom(Create8x8FloatData());
BufferHolder dest = new BufferHolder();
var dest = new BufferHolder();
this.Output.WriteLine($"TranposeInto_PinningImpl_Benchmark X {Times} ...");
Stopwatch sw = Stopwatch.StartNew();
var sw = Stopwatch.StartNew();
for (int i = 0; i < Times; i++)
{
@ -226,7 +226,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public unsafe void CopyColorsTo()
{
float[] data = Create8x8FloatData();
Block8x8F block = new Block8x8F();
var block = new Block8x8F();
block.LoadFrom(data);
block.MultiplyAllInplace(5);
@ -237,7 +237,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
byte[] colorsExpected = new byte[stride * height];
byte[] colorsActual = new byte[stride * height];
Block8x8F temp = new Block8x8F();
var temp = new Block8x8F();
ReferenceImplementations.CopyColorsTo(ref block, new Span<byte>(colorsExpected, offset), stride);
@ -303,18 +303,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[InlineData(2)]
public unsafe void UnzigDivRound(int seed)
{
Block8x8F block = new Block8x8F();
var block = new Block8x8F();
block.LoadFrom(Create8x8RoundedRandomFloatData(-2000, 2000, seed));
Block8x8F qt = new Block8x8F();
var qt = new Block8x8F();
qt.LoadFrom(Create8x8RoundedRandomFloatData(-2000, 2000, seed));
UnzigData unzig = UnzigData.Create();
var unzig = UnzigData.Create();
int* expectedResults = stackalloc int[Block8x8F.Size];
ReferenceImplementations.UnZigDivRoundRational(&block, expectedResults, &qt, unzig.Data);
Block8x8F actualResults = default(Block8x8F);
var actualResults = default(Block8x8F);
Block8x8F.UnzigDivRound(&block, &actualResults, &qt, unzig.Data);

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

@ -280,12 +280,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Fact]
public void Decode_IgnoreMetadataIsFalse_ExifProfileIsRead()
{
JpegDecoder decoder = new JpegDecoder()
var decoder = new JpegDecoder()
{
IgnoreMetadata = false
};
TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
var testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
using (Image<Rgba32> image = testFile.CreateImage(decoder))
{
@ -296,12 +296,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Fact]
public void Decode_IgnoreMetadataIsTrue_ExifProfileIgnored()
{
JpegDecoder options = new JpegDecoder()
var options = new JpegDecoder()
{
IgnoreMetadata = true
};
TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
var testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan);
using (Image<Rgba32> image = testFile.CreateImage(options))
{

5
tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -1,9 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using Xunit;
@ -12,7 +9,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
public class AutoOrientTests : BaseImageOperationsExtensionTest
{
[Fact]
public void AutoOrient_AutoRotateProcessor()
public void AutoOrient_AutoOrientProcessor()
{
this.operations.AutoOrient();
this.Verify<AutoOrientProcessor<Rgba32>>();

Loading…
Cancel
Save