Browse Source

Alpha8 => A8

af/merge-core
James Jackson-South 6 years ago
parent
commit
0acf4f979c
  1. 2
      src/ImageSharp/Advanced/AotCompilerTools.cs
  2. 44
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  3. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs
  4. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs
  5. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
  6. 6
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  7. 48
      tests/ImageSharp.Tests/PixelFormats/A8Tests.cs
  8. 2
      tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs
  9. 4
      tests/ImageSharp.Tests/TestImages.cs
  10. 2
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  11. 4
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  12. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  13. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

2
src/ImageSharp/Advanced/AotCompilerTools.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Advanced
/// </summary> /// </summary>
private static void SeedEverything() private static void SeedEverything()
{ {
Seed<Alpha8>(); Seed<A8>();
Seed<Argb32>(); Seed<Argb32>();
Seed<Bgr24>(); Seed<Bgr24>();
Seed<Bgr565>(); Seed<Bgr565>();

44
src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs → src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -8,56 +8,56 @@ using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.PixelFormats namespace SixLabors.ImageSharp.PixelFormats
{ {
/// <summary> /// <summary>
/// Packed pixel type containing a single 8 bit normalized W values. /// Packed pixel type containing a single 8 bit normalized alpha value.
/// <para> /// <para>
/// Ranges from [0, 0, 0, 0] to [0, 0, 0, 1] in vector form. /// Ranges from [0, 0, 0, 0] to [0, 0, 0, 1] in vector form.
/// </para> /// </para>
/// </summary> /// </summary>
public struct Alpha8 : IPixel<Alpha8>, IPackedVector<byte> public struct A8 : IPixel<A8>, IPackedVector<byte>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Alpha8"/> struct. /// Initializes a new instance of the <see cref="A8"/> struct.
/// </summary> /// </summary>
/// <param name="alpha">The alpha component.</param> /// <param name="alpha">The alpha component.</param>
public Alpha8(byte alpha) => this.PackedValue = alpha; public A8(byte alpha) => this.PackedValue = alpha;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Alpha8"/> struct. /// Initializes a new instance of the <see cref="A8"/> struct.
/// </summary> /// </summary>
/// <param name="alpha">The alpha component.</param> /// <param name="alpha">The alpha component.</param>
public Alpha8(float alpha) => this.PackedValue = Pack(alpha); public A8(float alpha) => this.PackedValue = Pack(alpha);
/// <inheritdoc /> /// <inheritdoc />
public byte PackedValue { get; set; } public byte PackedValue { get; set; }
/// <summary> /// <summary>
/// Compares two <see cref="Alpha8"/> objects for equality. /// Compares two <see cref="A8"/> objects for equality.
/// </summary> /// </summary>
/// <param name="left"> /// <param name="left">
/// The <see cref="Alpha8"/> on the left side of the operand. /// The <see cref="A8"/> on the left side of the operand.
/// </param> /// </param>
/// <param name="right"> /// <param name="right">
/// The <see cref="Alpha8"/> on the right side of the operand. /// The <see cref="A8"/> on the right side of the operand.
/// </param> /// </param>
/// <returns> /// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false. /// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns> /// </returns>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public static bool operator ==(Alpha8 left, Alpha8 right) => left.Equals(right); public static bool operator ==(A8 left, A8 right) => left.Equals(right);
/// <summary> /// <summary>
/// Compares two <see cref="Alpha8"/> objects for equality. /// Compares two <see cref="A8"/> objects for equality.
/// </summary> /// </summary>
/// <param name="left">The <see cref="Alpha8"/> on the left side of the operand.</param> /// <param name="left">The <see cref="A8"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Alpha8"/> on the right side of the operand.</param> /// <param name="right">The <see cref="A8"/> on the right side of the operand.</param>
/// <returns> /// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false. /// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns> /// </returns>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Alpha8 left, Alpha8 right) => !left.Equals(right); public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc /> /// <inheritdoc />
public PixelOperations<Alpha8> CreatePixelOperations() => new PixelOperations<Alpha8>(); public PixelOperations<A8> CreatePixelOperations() => new PixelOperations<A8>();
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
@ -128,21 +128,21 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary> /// </summary>
/// <param name="obj">The object to compare.</param> /// <param name="obj">The object to compare.</param>
/// <returns>True if the object is equal to the packed vector.</returns> /// <returns>True if the object is equal to the packed vector.</returns>
public override bool Equals(object obj) => obj is Alpha8 other && this.Equals(other); public override bool Equals(object obj) => obj is A8 other && this.Equals(other);
/// <summary> /// <summary>
/// Compares another Alpha8 packed vector with the packed vector. /// Compares another A8 packed vector with the packed vector.
/// </summary> /// </summary>
/// <param name="other">The Alpha8 packed vector to compare.</param> /// <param name="other">The A8 packed vector to compare.</param>
/// <returns>True if the packed vectors are equal.</returns> /// <returns>True if the packed vectors are equal.</returns>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Alpha8 other) => this.PackedValue.Equals(other.PackedValue); public bool Equals(A8 other) => this.PackedValue.Equals(other.PackedValue);
/// <summary> /// <summary>
/// Gets a string representation of the packed vector. /// Gets a string representation of the packed vector.
/// </summary> /// </summary>
/// <returns>A string representation of the packed vector.</returns> /// <returns>A string representation of the packed vector.</returns>
public override string ToString() => $"Alpha8({this.PackedValue})"; public override string ToString() => $"A8({this.PackedValue})";
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
@ -156,4 +156,4 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private static byte Pack(float alpha) => (byte)Math.Round(alpha.Clamp(0, 1F) * 255F); private static byte Pack(float alpha) => (byte)Math.Round(alpha.Clamp(0, 1F) * 255F);
} }
} }

2
src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs

@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
IErrorDiffuser diffuser = this.definition.Diffuser; IErrorDiffuser diffuser = this.definition.Diffuser;
byte threshold = (byte)MathF.Round(this.definition.Threshold * 255F); byte threshold = (byte)MathF.Round(this.definition.Threshold * 255F);
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds()); var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
int startY = interest.Y; int startY = interest.Y;

2
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
TPixel upperColor = this.definition.UpperColor.ToPixel<TPixel>(); TPixel upperColor = this.definition.UpperColor.ToPixel<TPixel>();
TPixel lowerColor = this.definition.LowerColor.ToPixel<TPixel>(); TPixel lowerColor = this.definition.LowerColor.ToPixel<TPixel>();
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds()); var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
int startY = interest.Y; int startY = interest.Y;

2
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
int startX = interest.X; int startX = interest.X;
int endX = interest.Right; int endX = interest.Right;
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY);

6
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.VimImage2, TestImages.Png.VimImage2,
TestImages.Png.Rgb24BppTrans, TestImages.Png.Rgb24BppTrans,
TestImages.Png.GrayAlpha8Bit, TestImages.Png.GrayA8Bit,
TestImages.Png.Gray1BitTrans, TestImages.Png.Gray1BitTrans,
TestImages.Png.Bad.ZlibOverflow, TestImages.Png.Bad.ZlibOverflow,
TestImages.Png.Bad.ZlibOverflow2, TestImages.Png.Bad.ZlibOverflow2,
@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.GrayAlpha1BitInterlaced, TestImages.Png.GrayAlpha1BitInterlaced,
TestImages.Png.GrayAlpha2BitInterlaced, TestImages.Png.GrayAlpha2BitInterlaced,
TestImages.Png.Gray4BitInterlaced, TestImages.Png.Gray4BitInterlaced,
TestImages.Png.GrayAlpha8BitInterlaced TestImages.Png.GrayA8BitInterlaced
}; };
public static readonly string[] TestImagesIssue1014 = public static readonly string[] TestImagesIssue1014 =
@ -180,7 +180,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
} }
[Theory] [Theory]
[WithFile(TestImages.Png.GrayAlpha8BitInterlaced, PixelTypes)] [WithFile(TestImages.Png.GrayA8BitInterlaced, PixelTypes)]
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider) public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {

48
tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs → tests/ImageSharp.Tests/PixelFormats/A8Tests.cs

@ -7,42 +7,42 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.PixelFormats namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
public class Alpha8Tests public class A8Tests
{ {
[Fact] [Fact]
public void Alpha8_Constructor() public void A8_Constructor()
{ {
// Test the limits. // Test the limits.
Assert.Equal(byte.MinValue, new Alpha8(0F).PackedValue); Assert.Equal(byte.MinValue, new A8(0F).PackedValue);
Assert.Equal(byte.MaxValue, new Alpha8(1F).PackedValue); Assert.Equal(byte.MaxValue, new A8(1F).PackedValue);
// Test clamping. // Test clamping.
Assert.Equal(byte.MinValue, new Alpha8(-1234F).PackedValue); Assert.Equal(byte.MinValue, new A8(-1234F).PackedValue);
Assert.Equal(byte.MaxValue, new Alpha8(1234F).PackedValue); Assert.Equal(byte.MaxValue, new A8(1234F).PackedValue);
// Test ordering // Test ordering
Assert.Equal(124, new Alpha8(124F / byte.MaxValue).PackedValue); Assert.Equal(124, new A8(124F / byte.MaxValue).PackedValue);
Assert.Equal(26, new Alpha8(0.1F).PackedValue); Assert.Equal(26, new A8(0.1F).PackedValue);
} }
[Fact] [Fact]
public void Alpha8_Equality() public void A8_Equality()
{ {
var left = new Alpha8(16); var left = new A8(16);
var right = new Alpha8(32); var right = new A8(32);
Assert.True(left == new Alpha8(16)); Assert.True(left == new A8(16));
Assert.True(left != right); Assert.True(left != right);
Assert.Equal(left, (object)new Alpha8(16)); Assert.Equal(left, (object)new A8(16));
} }
[Fact] [Fact]
public void Alpha8_FromScaledVector4() public void A8_FromScaledVector4()
{ {
// Arrange // Arrange
Alpha8 alpha = default; A8 alpha = default;
int expected = 128; int expected = 128;
Vector4 scaled = new Alpha8(.5F).ToScaledVector4(); Vector4 scaled = new A8(.5F).ToScaledVector4();
// Act // Act
alpha.FromScaledVector4(scaled); alpha.FromScaledVector4(scaled);
@ -53,10 +53,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
} }
[Fact] [Fact]
public void Alpha8_ToScaledVector4() public void A8_ToScaledVector4()
{ {
// Arrange // Arrange
var alpha = new Alpha8(.5F); var alpha = new A8(.5F);
// Act // Act
Vector4 actual = alpha.ToScaledVector4(); Vector4 actual = alpha.ToScaledVector4();
@ -69,10 +69,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
} }
[Fact] [Fact]
public void Alpha8_ToVector4() public void A8_ToVector4()
{ {
// Arrange // Arrange
var alpha = new Alpha8(.5F); var alpha = new A8(.5F);
// Act // Act
var actual = alpha.ToVector4(); var actual = alpha.ToVector4();
@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
} }
[Fact] [Fact]
public void Alpha8_ToRgba32() public void A8_ToRgba32()
{ {
var input = new Alpha8(128); var input = new A8(128);
var expected = new Rgba32(0, 0, 0, 128); var expected = new Rgba32(0, 0, 0, 128);
Rgba32 actual = default; Rgba32 actual = default;
@ -96,10 +96,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
} }
[Fact] [Fact]
public void Alpha8_FromBgra5551() public void A8_FromBgra5551()
{ {
// arrange // arrange
var alpha = default(Alpha8); var alpha = default(A8);
byte expected = byte.MaxValue; byte expected = byte.MaxValue;
// act // act

2
tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
int xy = 1; int xy = 1;
using (var img = new Image<Alpha8>(xy, xy)) using (var img = new Image<A8>(xy, xy))
{ {
var profile = new ExifProfile(); var profile = new ExifProfile();
img.Metadata.ExifProfile = profile; img.Metadata.ExifProfile = profile;

4
tests/ImageSharp.Tests/TestImages.cs

@ -28,8 +28,8 @@ namespace SixLabors.ImageSharp.Tests
public const string Bpp1 = "Png/bpp1.png"; public const string Bpp1 = "Png/bpp1.png";
public const string Gray4Bpp = "Png/gray_4bpp.png"; public const string Gray4Bpp = "Png/gray_4bpp.png";
public const string Gray16Bit = "Png/gray-16.png"; public const string Gray16Bit = "Png/gray-16.png";
public const string GrayAlpha8Bit = "Png/gray-alpha-8.png"; public const string GrayA8Bit = "Png/gray-alpha-8.png";
public const string GrayAlpha8BitInterlaced = "Png/rollsroyce.png"; public const string GrayA8BitInterlaced = "Png/rollsroyce.png";
public const string GrayAlpha1BitInterlaced = "Png/iftbbn0g01.png"; public const string GrayAlpha1BitInterlaced = "Png/iftbbn0g01.png";
public const string GrayAlpha2BitInterlaced = "Png/iftbbn0g02.png"; public const string GrayAlpha2BitInterlaced = "Png/iftbbn0g02.png";
public const string Gray4BitInterlaced = "Png/iftbbn0g04.png"; public const string Gray4BitInterlaced = "Png/iftbbn0g04.png";

2
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
Undefined = 0, Undefined = 0,
Alpha8 = 1 << 0, A8 = 1 << 0,
Argb32 = 1 << 1, Argb32 = 1 << 1,

4
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -39,8 +39,8 @@ namespace SixLabors.ImageSharp.Tests
ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32; ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32;
// Add PixelFormat types // Add PixelFormat types
string nameSpace = typeof(Alpha8).FullName; string nameSpace = typeof(A8).FullName;
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Alpha8).Name.Length - 1); nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(A8).Name.Length - 1);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.Rgba32)) foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.Rgba32))
{ {
string typeName = $"{nameSpace}.{pt}"; string typeName = $"{nameSpace}.{pt}";

2
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory] [Theory]
[WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)] [WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)]
[WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)] [WithBlankImages(1, 1, PixelTypes.A8, PixelTypes.A8)]
[WithBlankImages(1, 1, PixelTypes.Argb32, PixelTypes.Argb32)] [WithBlankImages(1, 1, PixelTypes.Argb32, PixelTypes.Argb32)]
public void PixelType_PropertyValueIsCorrect<TPixel>(TestImageProvider<TPixel> provider, PixelTypes expected) public void PixelType_PropertyValueIsCorrect<TPixel>(TestImageProvider<TPixel> provider, PixelTypes expected)
where TPixel : struct, IPixel<TPixel> => where TPixel : struct, IPixel<TPixel> =>

4
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -99,13 +99,13 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void ExpandAllTypes_1() public void ExpandAllTypes_1()
{ {
PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32; PixelTypes pixelTypes = PixelTypes.A8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32;
IEnumerable<KeyValuePair<PixelTypes, Type>> expanded = pixelTypes.ExpandAllTypes(); IEnumerable<KeyValuePair<PixelTypes, Type>> expanded = pixelTypes.ExpandAllTypes();
Assert.Equal(4, expanded.Count()); Assert.Equal(4, expanded.Count());
AssertContainsPixelType<Alpha8>(PixelTypes.Alpha8, expanded); AssertContainsPixelType<A8>(PixelTypes.A8, expanded);
AssertContainsPixelType<Bgr565>(PixelTypes.Bgr565, expanded); AssertContainsPixelType<Bgr565>(PixelTypes.Bgr565, expanded);
AssertContainsPixelType<HalfVector2>(PixelTypes.HalfVector2, expanded); AssertContainsPixelType<HalfVector2>(PixelTypes.HalfVector2, expanded);
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded); AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);

Loading…
Cancel
Save